0

I have started C programming with Eclipse.

According to the image, these functions dont work correctly :(

I expected the output will be:

enter the 1st number: 45

enter the 2st number: 21

1st num is 45 and 2st num is 21

but output is something else, it seems that scanf functions work first, then printf functions work...

Does anybody know where is the problem? Is this problem from compiler or another thing? :(

thanks.

SHOW THE IMAGE

  • 2
    Please post code and input/output as text. See [here](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors) for why. – Phil M Feb 22 '19 at 22:59
  • 2
    Don't post images of code. Try `fflush(stdout);` after your `printf()` – pmg Feb 22 '19 at 23:00
  • 1
    Whenever you start a question with "This C-library function" does not work... 99.9999% of the time, it's not the C function at fault. Your code snippet is fine (aside from failure to provide a `'\n'` at the end of your last output). The program is doing exactly what you have told it to do. No? – David C. Rankin Feb 22 '19 at 23:00
  • The output looks exactly like you are piping the numbers to your program instead of entering them as input, e.g. `echo "45 21" | ./bin/scanf_mn` results in `"enter the 1st number: enter the 2nd number: 1st num is 45 and 2nd num is 21"` while entering the numbers at the prompt provides the correct output. How are you entering `45` and `21`? (this may be Eclipse doing this if you are entering `45` and `21` in some dialog Eclipse provides instead of running your program in a terminal and inputting the values when the program asks for them) – David C. Rankin Feb 22 '19 at 23:08
  • @DavidC.Rankin No need to be so pedantic. Whenever someone writes "X doesn't work", what they really mean is "X doesn't work as I expect it to". – Barmar Feb 22 '19 at 23:14

0 Answers0