int x,y,m;
for(;;){
m=scanf("%d %d",&x,&y);
if (m!=2 || m==EOF){
break;
}
else{
printf("/%d/%d/\n",x,y);
}
}
if (feof ( stdin )){
printf("End of input\n");
}else if(m!=2){
printf("There was an error\n");
}
在linux下ctrl + D表示输入结束,而对于windows ctrl + z应该做的伎俩,但它不起作用。有什么想法吗?
答案 0 :(得分:5)
尝试按Ctrl + z
后按Enter键如果仍然没有运气,请尝试使用C ++版本:
#include <iostream>
int x, y;
while ( std::cin >> x >> y )
std::cout << '/' << x << '/' << y << "/\n";
if ( std::cin.eof() )
std::cout << "End of input\n";
else
std::cout << "There was an error\n";
看看它是否做得更好?
答案 1 :(得分:-2)
#include<stdio.h>
#include<conio.h>
void main (void)
{
int x,y,m;
for(x=0;x>=0;x++){
m=scanf("%d %d",&x,&y);
if (m!=2 || m==EOF){
break;
}
else printf("/%d/%d/\n",x,y);
}
if (feof ( stdin )){
printf("End of input\n");
}
else if(m!=2){
printf("There was an error\n");
}
getch();
}