Thursday 19 October 2017

c - I input Ctrl - D (EOF) when called scanf(), then next scanf ignored

itemprop="text">

I input Ctrl - D (EOF) when called
scanf(), then next scanf
ignored.




#include


int main()
{
int
input;
scanf("%d", &input);//I press Ctrl-D when this line

scanf("%d", &input);//this line just passed. not read my input. why?

return
0;


}


I
want get input with scanf() second called.
What's is a
problem?



Answer




it seems that your code is OK. The only think
is to remember to press "return" at the end of both input number. I rewrite your code in
a "better" way:



#include

int main(){


int
input1,input2;
printf("Digit the first number: ");
scanf("%i",
&input1);//Press return at the end
printf("Digit the second number:
");
scanf("%i", &input2);//Press return at the
end
printf("input1:%i\tinput2:%i\n",input1,input2);
return
0;
}



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...