为什么循环的退出条件只有在单独输入EOF的时候才有效?
为什么前面输入字符再输入EOF的话会输出奇怪的东西(c is't a letter. -1)?
//程序从标准输入读取字符,直到遇到文件结尾。程序检查并报告该字符是否是一个字母。如果是的话,程序还应该报告该字母在字母表中的位置,否则返回-1
#include<stdio.h>
#include<ctype.h>
int main (void)
{
char ch = NULL;
while ((ch = getchar()) != EOF){
if (!isalpha(ch))
printf("%c isn't a lettter. -1\n");
else{
if(isupper(ch))
printf("%c is the %d in the alphabet\n",
ch, ch - 'A' +1);
else
printf("%c is the %d in the alphabet\n",
ch, ch - 'a' +1);
}
}
printf("Done.\n");
return 0;
}