windows - Using EOF and getchar() for character counting in C -
possible duplicate:
why doesn't getchar() recognise return eof in windows console?
i'm new in c , trying figure out how eof , getchar() works.
#include <stdio.h> main() { int number = 0; while(getchar() != eof) number++; printf("%d", number); } when type random characters, program doesn't anything, think never gets out of while loop. why that? i'm using codeblocks on windows 7.
because aren't sending eof character. "eof" stands "end-of-file"; console input (known "standard input") special case of file. in order denote special file has ended, need send special signal. can effect on windows pressing ctrl+z (followed enter, reason).
Comments
Post a Comment