so sorry if I am a little confused.
I am trying to fill out an array of structs with values I read in from an input file. I am having no trouble reading in the values from the file. But when the file is very small and does not fill the array completely, the remaining structs have random values in them, and I would like to completely set these structs to NULL. I am attempting to do this because I would like to run through this filled out array of structs and print its values, and I need to see which array values are legitimately from the file.
Here is my code so far
struct function {
char name[20];
int parameterNumer;
};
int main(int argc, const char * argv[])
{
struct function functionList[10];
int i =0, j;
int portNumber;
char *configFile = argv[1];
FILE *fp;
fp = fopen(configFile, "r");
if(fp == NULL) {
perror("File not found");
exit(1);
}
fscanf(fp, "%d", &portNumber);
while(fscanf(fp, "%s %d", functionList[i].name, &functionList[i].parameterNumer) == 2) {
i++;
}
functionList[i] = NULL; //getting an error here
for(j = 0; functionList[j] != NULL; j++) { //and here
printf("%s %d", functionList[j].name, &functionList[j].parameterNumer);
}
return 0;
}