What is the best (shortest) way to read the next non-blank (not space/newline/tab) character from a file in a C program?
I realize I could probably use gets followed by strtok, but it seems like there has to be somethi开发者_StackOverflowng more concise.
If so, let me know; if not, let me know that too.
Thanks.
char c;
fscanf(f, " %c", &c);
OR
int c;
while (isspace(c=fgetc(f)));
The next character can be read using fgetc
. Since you cannot know in advance whether it is blank or not, you have to take the risk and read it. If it then turns out not to be non-blank, you can put it back using fputc
.
精彩评论