Question

    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");
}

Under linux ctrl+D indicates end of input , and for windows ctrl+z is supposed to do the trick, but it doesn't work. Any ideas?

Was it helpful?

Solution

Try pressing Enter after Ctrl+z

If still no luck, please try the C++ version:

#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";

and see if it does better?

OTHER TIPS

#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();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top