I have a problem while passing a ptr to the function loadSignatures. at the end of loadSignatures function the virusList has the address I wish, but then it returns to the main with unexpected address.
void loadSignatures(char* fileName, link* virusList){
FILE* f = fopen(fileName, "rb");
virus* v = readVirus(f);
while (v){
virusList = list_append(virusList,v);
v = readVirus(f);
}
fclose(f);
}
int main(int argc, char **argv) {
link *virusList = NULL;
char fileName[30];
gets(fileName);
loadSignatures(fileName, virusList);
list_print(virusList, stdout);
list_free(virusList);
}
even when I try to do this:
link* loadSignatures(char* fileName, link* virusList){
FILE* f = fopen(fileName, "rb");
virus* v = readVirus(f);
while (v){
virusList = list_append(virusList,v);
v = readVirus(f);
}
fclose(f);
return virusList;
}
int main(int argc, char **argv) {
link *virusList = NULL;
char fileName[30];
gets(fileName);
virusList = loadSignatures(fileName, virusList);
list_print(virusList, stdout);
list_free(virusList);
}
It doesn't work properly.
I will be glad to know the right way to deal with this issue.