c - Parsing a text file - any reason why space / new line would be ignored? -
i have while loop...
char count[3] = {0}; int = 0; while( c != ' ' || c != '\n' || c != '\t' ) { count[i] = c; c = fgetc(fp); i++; }
and though see while debugging space , newline right ascii numbers, while loop not exit. know causing this?
the logic in conditional not right. evaluate true
time.
while( c != ' ' || c != '\n' || c != '\t' )
if c
equal ' '
not equal '\n'
or '\t'
.
what need is:
while( c != ' ' && c != '\n' && c != '\t' )
and measure, add c != eof
.
while( c != ' ' && c != '\n' && c != '\t' && c != eof )
it might simpler use:
while( !isspace(c) && c != eof )
Comments
Post a Comment