s-macke / jor1k

Online OR1K Emulator running Linux
http://jor1k.com
BSD 2-Clause "Simplified" License
1.73k stars 193 forks source link

C program scanf() and printf() interrupt #158

Closed alexwenbj closed 4 years ago

alexwenbj commented 4 years ago

When I compile and run this program:

#include <stdio.h>
int main()
{
    float f;
    printf("Enter a number: ");
    scanf("%f",&f);
    printf("Value = %f", f);
    return 0;
}

The behavior is not expected: it suspend to wait for input without the output:"Enter a number:",when I input data and press enter,the "Enter a number:" and "Value = ..." output at the same line.

andrakis commented 4 years ago

It appears that output buffering on stdout is on by default. Different platforms will have different defaults.

There are a few solutions that all work, and the simplest is:

    printf("Enter a number: ");
    fflush(stdout);
    scanf("%f",&f);
alexwenbj commented 4 years ago

@andrakis Thank you.It works. BTW:Is there any way to set up this default value in jor1k?