Newlib printf/scanf problems.
Posted: Fri Dec 07, 2012 11:39 am
I recently got newlib working for my OS and compiled a simple program with a cross compiler:
Now this prints out the message and then reads from file descriptor 0. This seems ok as 0 is stdin. (The output is a write to fd 1).
However, no matter what number I enter it just reads 1024 bytes from stdin again. Is this expected behaviour???
Moreover, and more worrying, when the scanf is excluded, no write syscall occurs. Ie a program that only printfs has no effect. BUT a program that prints to stderr (fprintf(stderr,"Hello")) makes the syscall.
Afaik, the only difference between stdio and stderr wrt an application is that the one is buffered and the other not. But surely both must get written at some time. Am I missing something?
Code: Select all
int main()
{
printf("Hello world (input a number): ");
int a = 7;
scanf("%d",&a);
printf("%d",a);
return 0;
}
However, no matter what number I enter it just reads 1024 bytes from stdin again. Is this expected behaviour???
Moreover, and more worrying, when the scanf is excluded, no write syscall occurs. Ie a program that only printfs has no effect. BUT a program that prints to stderr (fprintf(stderr,"Hello")) makes the syscall.
Afaik, the only difference between stdio and stderr wrt an application is that the one is buffered and the other not. But surely both must get written at some time. Am I missing something?