Dynamic memory allocation for structs passed to function
Hi,
I have to make a program that acts as a spam filter, and part of the program has to dynamicly allocate memroy to a member of a struct that is passed to a function..
But I'm doing it quite wrong..
What I have is as follows..
(PS this is FAR from complete, but as you can see I'm just doing the memory allocation completely wrong..)
Code:
typedef struct {
double weight;
char *word;
} feature;
typedef struct {
feature *features;
int size;
} dictionary;
void dictionary_read(dictionary *dict, const char *filename){
FILE* bestand;
double aantal; //aantal = amount in dutch
bestand = fopen(filename,"r");
fscanf(bestand,"%lf", &aantal);
dict->features = (dict->features)calloc(aantal,sizeof(dict->features));
fclose(bestand);
}
Kind regards.