I have the following code
and the problem is when I run it, each time through the loop it will still retain what was left over if the previous loop had more chars. I want to blank out this pointer each time through the loop so I will get clean results. I thought using free() would help, but it did nothing.
Code:
int parseFile(FILE* fp, char s[]) {
char *buffer;
int c, i;
i = 0;
buffer = (char*)malloc(MAX_ARRAY+1);
while ((c = getc(fp)) != EOF) {
while (!isspace(c)) {
*(buffer+i) = c;
i++;
c = getc(fp);
}
i = 0;
if (strcmp(buffer, s) == 0) {
return 0; /* found */
}
}
return 1; /* not found */
}
Comment