I'm trying to read in the dictionary with a name and a number, but it doesn't work. I'm doing a lot of mistakes... Can somebody point out where I need to correct?
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "Dictionary.h"
int count=0;
int main(){
dic dicptrs[20];
char k[20], v[20];
int insert;
dicptrs[count]= CreateDictionary();
printf("Enter a name:");
scanf("%s", &k);
printf("Enter a number:");
scanf("%s", &v);
insert = InsertEntries(dicptrs[20],k,v);
printf("%s and %s\n", dicptrs->keys, dicptrs->values);
}
/****************CreateDictionary******************************/
Dictionary* CreateDictionary(void){
/* Pre: True
* Post: size of dictionary = 0 && count = 0
*/
dic dicptr;
dicptr = (Dictionary*) malloc(sizeof(Dictionary));
dicptr->keys = dicptr->values = NULL;
return dicptr;
}
/***************InsertEntries********************************/
int InsertEntries(Dictionary* dicptr, char key[], char value[]){
strcpy(dicptr->keys,key);
strcpy(dicptr->values,value);
return 1;
}
And here is the header file:
Code:
#ifndef DICTIONARY_HDR
#define DICTIONARY_HDR
typedef struct dictionary {
char* keys[20];
char* values[20];
int count;
} Dictionary, *dic;
Dictionary* CreateDictionary(void);
/* Pre: True
* Post: size of dictionary = 0 && count = 0
*/
int InsertEntries(Dictionary *dic,char[], char value[]);
/* Pre: size dic >=0
* Post: Return 1 if the insertion was perfomed and 0 otherwise
* size dic = size dic0+1
*/
#Endif