Search

4/03/2006

getchar()

main(){
char c;

while((c=getchar()) != EOF)
putchar(c);
}

getchar returns an integer
The getchar function returns the next character from the standard input,
or EOF(a value, defined in stdio.h, which is distinct from any character)
if there is no input left.
在VC中EOF的值為-1,如果用char不帶正負號,則這個程式會出錯。
正確的寫法應該宣告c為int

#define getchar() getc(stdin)

沒有留言: