1

Hello I'm the beginner of programming c. I'm studying c with the book and doing copy the book for basic learning. Some coding was running and showed the output but Some coding also was running tho didn't show the output. Can you help me? this is my first question of coding and I'm not really good at English so sorry for not including details about my question.

This is my code and this was running but didn't give output:

#include <stdio.h>

int main(void)
{
    double num1, num2;
    printf("print: ");
    scanf("%lf %lf", &num1, &num2);

    printf("plus: %f \n", num1+num2);
    return 0;

}

This is not only running but also gave output:

#include <stdio.h>
int main(void)
{
    printf("hello world\n");`

    return 0;
}
Bodo
  • 9,287
  • 1
  • 13
  • 29
Chris Hong
  • 11
  • 2
  • 1
    What was the input you used? This seems to work: https://ideone.com/t7iPWx – Retired Ninja Jul 19 '21 at 05:27
  • 1
    *How* are you running your program? What environment are you using? Does the first example not give any output at all, not even the `print:` prompt? – Some programmer dude Jul 19 '21 at 05:28
  • Add `fflush(stdout);` after the `printf("print: ");` – kaylum Jul 19 '21 at 05:28
  • 1
    Does this answer your question? [Why does printf not flush after the call unless a newline is in the format string?](https://stackoverflow.com/questions/1716296/why-does-printf-not-flush-after-the-call-unless-a-newline-is-in-the-format-strin) – kaylum Jul 19 '21 at 05:31
  • Did running the first code terminate without output? Or did you start it, did not see any output and then terminated it forcefully? – Yunnosch Jul 19 '21 at 05:34
  • I did fflush(stdout); but it didn't work. – Chris Hong Jul 19 '21 at 06:01
  • I just right-clicked and clicked the 'run code'. I'm using visual studio code at MacBook and yes it didn't give any output at all – Chris Hong Jul 19 '21 at 06:04
  • @ChrisHongPlease [edit] your question and add requested information or clarification there. Please also show the input you used. – Bodo Jul 19 '21 at 06:42

0 Answers0