问题描述
我是编程新手,特别是 getchar() 或 EOF。我在 K&R 中测试了一个使用 EOF 作为终止条件的示例。
#include <stdio.h>
#define EOF 'A'
int main(){
int c,i,nwhite,nother,ndigit[10];
nwhite = nother =0;
for(i = 0; i < 10; i++){
ndigit[i] = 0;
}
while((c = getchar()) != EOF){
switch(c){
case '0' : case '1' : case '2' : case '3' : case '4' : case '5' :
case '6' : case '7' : case '8' : case '9' :
ndigit[c - '0']++;
break;
case ' ' : case '\n' : case '\t' :
nwhite++;
break;
default :
nother++;
break;
}
}
printf("digits =");
for(i = 0; i < 10; i++){
printf(" %d",ndigit[i]);
}
printf(",white spaces = %d,other = %d\n",nother);
return 0;
}
但是我无法在 vscode Windows 中输入 EOF。我已经在其他地方尝试过 [Ctrl+D]、[Ctrl+Z] 和其他建议的答案。
当我将 EOF 定义为“A”之类的东西时,它会发出重新定义的警告,但程序完全按预期工作。
警告说的是默认的 stdio.h 值 #define EOF (-1)
,我也输入了 (-1) 但仍然不起作用
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)