Mail Archives: djgpp-workers/1998/08/26/12:39:33
Dear colleagues,
Please help me with this problem: the following program should run
correctly, and it runs in others compilers.
But in DJGPP we had problems when our programs use scanf("%c", &x)
mixed with scanf("%d", &y) or scanf("%f", &z), the first one is
not runned sucessfully.
I tried to use fflush(stdin), but, like Nate Eldredge told me,
"ANSI says that the effect of fflush'ing an input stream is undefined",
and this idea didn't work.
What could be the correct way to use scanf safely?
Thank you in advance.
Carlos Menezes.
#include<stdio.h>
main()
{
int a, b, c;
char d;
scanf("%d%d", &a, &b);
scanf("%c", &d);
if (c=='y') c=a*b;
else c=a+b;
printf("\n%d\n", c);
}
Carlos Menezes -- Tycho Brahe Project
LABORATORIO DE SISTEMAS INTEGRAVEIS.
ESCOLA POLITECNICA DA UNIVERSIDADE DE SAO PAULO.
E-MAIL: menezes AT lsi DOT usp DOT br
URL: http://www.lsi.usp.br/~menezes/menezes.html
- Raw text -