at the moment i have a project for the studies and me and a friend don't really know on how resolve the problem on a part of this.
So, it's a C project. I have 2 struct :
struct Lib {
char letter;
int capacity;
int size;
char** words[200000];
};
typedef struct Lib Library;
struct Program {
char* loadedFileName[50];
FILE* f;
Library* dictionary;
int totalwords;
};
typedef struct Program Program;
And this function :
void fillDicoFromFile(Program* startup){
rewind(startup->f);
while(!feof(startup->f) && !ferror(startup->f)){
char* word = malloc(sizeof(char) * 30);
fscanf(startup->f, "%s", word);
int indexLib = word[0] - 97;
int sizeLib = startup->dictionary[indexLib].size;
startup->dictionary[indexLib].words[sizeLib] = (char*)malloc(sizeof(char) * (strlen(word)+1));
startup->dictionary[indexLib].words[sizeLib] = word;
startup->dictionary[indexLib].size++;
free(word);
}
CountTotalWords(startup);
}
startup->dictionary is a array of 26 Library, and when i get a word from the file, i check his first letter and select the good Library (startup->dictionary[0] for 'a' ...) and then put the word on the array "word" of the struct, but when i want printf some words, it's bugged strings or wrongs one. I'm pretty sure we're doing wrong on pointers but where ...
What are we doing wrong ?