mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-22 21:41:59 +03:00
49 lines
1.0 KiB
C
49 lines
1.0 KiB
C
|
/*
|
||
|
author: Christian Bender
|
||
|
This is a simple test program for the dictionary.
|
||
|
*/
|
||
|
|
||
|
#include <stdio.h>
|
||
|
|
||
|
/* includes the dictionary */
|
||
|
#include "dict.h"
|
||
|
|
||
|
int main(void)
|
||
|
{
|
||
|
Dictionary * testObj1;
|
||
|
Dictionary * testObj2;
|
||
|
|
||
|
int value = 28;
|
||
|
|
||
|
testObj1 = create_dict();
|
||
|
testObj2 = create_dict();
|
||
|
|
||
|
add_item_label(testObj1,"age",&value);
|
||
|
add_item_label(testObj2,"name","Christian");
|
||
|
|
||
|
|
||
|
/*
|
||
|
test for function add_item_label
|
||
|
|
||
|
attention:
|
||
|
The void* pointer must be convert into an int* pointer.
|
||
|
After that you can dereference it.
|
||
|
*/
|
||
|
printf("My age is %d\n",*((int *)get_element_label(testObj1,"age")));
|
||
|
printf("My name is %s\n",get_element_label(testObj2,"name"));
|
||
|
|
||
|
/* test for function add_item_index */
|
||
|
if (!add_item_index(testObj1,0,&value))
|
||
|
{
|
||
|
printf("My age at index %d is %d\n",0,*((int *)get_element_index(testObj1,0)));
|
||
|
}
|
||
|
|
||
|
/* error scenario */
|
||
|
/* get_element_label(testObj,"none"); */
|
||
|
|
||
|
/* tidy up */
|
||
|
destroy(testObj1);
|
||
|
destroy(testObj2);
|
||
|
|
||
|
return 0;
|
||
|
}
|