tags:

views:

49

answers:

2

Hi I have this code

    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?

A: 

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?

usta
Nope, doesn't work. it just freezes after ctrl+z, no more input possible, not even enter.
Randalfien
BTW do you think that scanf doesnt return EOF ? cause all the examples from web work with getchar ..but since I need integers , I don't want to use that..
Randalfien
@Randalfien: scanf will return EOF when end-of-file is occurred.
usta
@Randalfien: Ctrl+z followed by Enter works for me with your code, VC 10 Express and XP SP3. What compiler do you use?
usta
I use NetBeans, thats gcc compiler , I run Win7 .. Can it be, that I have something wrong with my compiler comfiguration?
Randalfien
@Randalfien: Let's do a quick check with C++. Please see my edited answer for that.
usta
Ok , I've typed in your code and it acts just like before. When I press ctrl z , enter it does nothing, and input is no longer possible, I presume it works for you just fine, right? so it must be some bad configuration ? (BTW thanks very much for all the advice !)
Randalfien
@Randalfien: Yes, they work fine with my configuration. I'll try to find some time to try this with gcc under windows. That is weird...
usta
@Randalfien: I checked with mingw, gcc 4.3.0 on Windows XP SP2 and both of the examples worked just fine -- after Ctrl-z followed by Enter "End of input" was printed and program exited. So that must be an environment/configuration issue I guess.
usta