I did this function for get a word from a file until reaching EOF.
I can compile it without error message, but when I try to run it, it looks to take longtime. I think my loop has problem, who can help me to work out?
here is the code:
#include <ctype.h>
#include <stdio.h>
#include <string.h>
char *getword(FILE *fp)
{
char ch;
char *w, *word;
char buf[BUFSIZ];
w = buf;
ch = fgetc(fp);
while( isspace(ch))
;
if(ch != EOF)
*w++ = ch;
*w = '\0';
word = strdup(w);
return word;
}



LinkBack URL
About LinkBacks



