scanf() acting strange
Tim Drury
tim.drury@gtri.gatech.edu
Mon Jul 6 07:25:00 GMT 1998
I think this came up a couple weeks ago and I thought
I saved the message(s) but I couldn't find them.
My platform is a mc68333 board and I'm using a Linux
to m68k cross-compiler. I have printf() working great,
but when I call scanf() it doesn't seem to get the
end-of-line character correctly.
For example, I have a loop which asks for a string, an
integer, and a float. It looks something like this:
char s[100]
int i;
float f;
while(1)
{
printf("enter a string:\n");
scanf("%s", s);
printf("you said %s.\n", s);
printf("enter an integer:\n");
scanf("%d", &i);
printf("you said %d.\n", i);
printf("enter a float:\n");
scanf("%f", &f);
printf("you said %f.\n", f);
}
And when I run it, the program waits for me to enter a string.
But when I hit the "enter" key nothing happens. If I hit it
again, the program continues, but doesn't ask for any more input -
it just keeps printing the following:
enter a string:
you said asdfs.
enter an integer:
you said: 0.
enter a float:
you said 0.0.
...
The string is correct, but the integer and float are never
prompted for. If I peek into my serial input buffer I see:
asdfs\r\r\0\0......\0
It is a 256 byte buffer. This looks correct - my string is
there terminated with \r and my second \r is in there too.
Why doesn't my program stop and ask for the integer and
the float?
I haven't touched read.c, but I re-wrote inbyte() to read
characters from my serial input buffer.
Any ideas?
-tim
More information about the crossgcc
mailing list