|
From: <and...@su...> - 2003-04-11 05:34:23
|
Dear programmers,
I´m having to use the fflush command in the following code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char name[10];
int a, b, c;
printf("Enter a-->");
scanf("%d", &a);
printf("Enter some name-->");
fflush(stdin);
gets(name);
printf("Enter com b-->");
scanf("%d", &b);
printf("The sum of %d with %d is %d\n", a, b, a+b);
printf("And the name typed was %s\n", name);
system("PAUSE");
return 0;
}
The reason is that if I don´t put it, the program doesn´t wait for the name
to be typed via keyboard. It passes directly to the other operator, b,
indicating that the input buffer is loaded with something. I made some
experiments with short int (hd), but nothing solved.
1-Can anyone explain what is happening?
2-What is the solution for don´t use the fflush?
Regards
Andre
|