提问人:Test Raw 提问时间:1/5/2021 最后编辑:BarmarTest Raw 更新时间:1/5/2021 访问量:126
如何输入eof(Ctrl + z),同时让scanf在说明符之前有一个空格以避免出现以前的\n错误?
How to input eof(Ctrl+z) while letting the scanf have a space before the specifier to avoid getting previous \n error?
问:
(我按回车键)
#include<stdio.h>
#include<stdlib.h>
int main(){
int target,result;
while(1){
printf("Please input your target: ");
scanf(" %d",&target);
if(feof(stdin)){
break;
}
printf("test\n");
}
}
如果我将代码更改为:(删除空格)
#include<stdio.h>
#include<stdlib.h>
int main(){
int target,result;
while(1){
printf("Please input your target: ");
scanf("%d",&target);//no space
if(feof(stdin)){
break;
}
printf("test\n");
}
}
成功了
答: 暂无答案
评论
%d
%d
\n
%s
还可以跳过空格来阅读一个单词。