0

I started learning C today through YouTube and I copied the code from a tutorial for testing and I get a completely different result.

My code:

It's supposed to ask for a user prompt to enter a value, the print that value with a different message

However, whenever I try to run the code, the user prompt doesn't show up and when I enter "3" as an answer, this happens enter image description here

Link to YouTuber's code with the timestamp. Any help would be greatly appreciated :)

kaylum
  • 11,347
  • 2
  • 20
  • 29

1 Answers1

1

Since you use scanf to wait for user input, it will wait until you give some input to the program.

printf doesn't put all of the characters to the screen immediately, it buffers it's output. And as long as your program doesn't terminate or you don't call flush(stdout) to flush the buffer or you don't put newline character \n at the end of first parameter to printf the output won't be printed to the screen.

change your call to printf to:

printf("Enter radius\n: ") use newline so that the string is printed immediately and buffer is flushed

or if you do not want to use newline

printf("Enter radius: ") fflush(stdout)

call fflush(stdout) to manually flush the output buffers.

Harianja Lundu
  • 127
  • 1
  • 7
  • Adding a new line didn't fix the issue but flushing the buffer did, thanks for the help :) It's strange, I cloned the code as-is onto my sister's MacBook and it worked perfectly without any alterations. I think it may be a compiler issue with Windows. – Alex the idiot Feb 15 '20 at 05:54