#Why doesn't \n print out the Buffer?

1 messages · Page 1 of 1 (latest)

sleek latch
#

`#include <stdio.h>

int main(int argc, char **argv) {

printf("Number: \n");
int number;
scanf("%d", &number);
printf("%d", number);
return 0;

}`
I thought that using \n forces the buffer to print "Number: " out. Why isn't this the case?

bright torrentBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

fallow dawn
#

You can force to flush the buffer by using fflush(stdout)
'\n' is just a character, doesn't force C to actually print it yet

#

However it is interesting that you don't see the Number: output, it usually would appear or at least I don't really know why it wouldn't.
Anyway, try it with the fflush, that'll work for sure

sleek latch
#

It only showes up, when I enter a Number and then press enter.
But thx for your help

fallow dawn
#
#include <stdio.h>

int main(int argc, char **argv) {

    printf("Number: \n");
    fflush(stdout);
    int number;
    scanf("%d", &number);
    printf("%d", number);
    return 0;
}
#

There, that's how I meant it

#

Could you try that code and see if it works?

sleek latch
#

yes it works thx

fallow dawn
#

👍

sleek latch
#

!solved