Scanf is not working in posix sample

Bogdan Vacaliuc bvacaliuc at
Sat May 21 12:36:25 UTC 2005

Hello Thomas, Jason,

Thomas is right that scanf() will not send any characters to stdout, but there should not be any reason that Jason should avoid the
'ordinary characters' in his conversion string.  See:

Particulary the treatment of ordinary characters, which are treated as follows:

"A directive that is an ordinary character shall be executed as follows: the next byte shall be read from the input and compared
with the byte that comprises the directive; if the comparison shows that they are not equivalent, the directive shall fail, and the
differing and subsequent bytes shall remain unread. Similarly, if end-of-file, an encoding error, or a read error prevents a
character from being read, the directive shall fail."

So the worst that could have happenend is that "nummer" would not have been initialized coming out of scanf().  Since in the
example, nummer was not used, the test should have exited normally with the end-of-test output string.

Did you remember to give the EOL character?  I believe stdin is line buffered by default?  If not, there might be something wrong in
the environment setup that prevents scanf() from operating correctly.  Is stdin setup and functional at all?  I.e. can you read 1

Best Regards,


On Saturday, May 21, 2005 2:13 AM, Thomas Doerfler wrote:

> Jason,
> it might have been late when you tried out this code, but... scanf
> does not work that way. You can't put a prompt text into the first
> parameter of scanf. Try out this one: replace your scanf line with:  
> 	printf("Eingabe: ");
> 	scanf("%d",&nummer);
> wkr,
> Thomas.
> Jason Davis schrieb:
>> Hello,
>> I modified a posix printf example slightly with an additional scanf.
>> But I can't figure out why the program is not running. It starts and
>> shows the printf "Hello World" string but the it stops without any
>> possible input via keyboard. I'm using a PC board with a PIII.
>> I added the test.c file and my makefile below. Any ideas?
>> Regards,
>> Jason
>> The test.c file:
>> /*
>>  *  Simple test program -- simplified version of sample test hello.
>> */ 
>> #include <bsp.h>
>> #include <stdlib.h>
>> #include <stdio.h>
>> #include <stdlib.h>
>> void *POSIX_Init(
>>   void *argument
>> )
>> {
>>   int nummer;
>>   printf( "\n\n*** HELLO WORLD TEST ***\n" );
>>   printf( "Hello World\n" );
>>   scanf("Eingabe: %d",&nummer);
>>   printf( "*** END OF HELLO WORLD TEST ***\n" );
>>   exit( 0 );
>> }

More information about the users mailing list