Re: [Dev-C++] RE : another Run Problem - to Charles
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Charles <cha...@at...> - 2001-12-04 22:28:59
|
Andre -
-------------------------------------
I just tested the solution that Ricardo Lopez Ruiz sent: replace
fflush(stdout) with fflush(sdtin) that finally seems to work fine.
So I suppose that I make a mistake somewhere else in the program. Please
let me know if you find it. Here is the full source:
#include <stdio.h>
main()
{
int i,n,som;
i = 0;
n = 0;
som = 0;
printf("\n==== Somme des n premiers multiples de 3 ====\n\nEntrez la
valeur de n : "); scanf("%d",&n); n=n*3;
while(n>i)
{
i+=3;
som=som+i;
}
printf("La somme est : %d\n",som);
printf("Taper ENTREE pour continuer...");
fflush(stdout);
getchar();
}
-------------------------------------
Well, this is interesting. I can see the problem but I don't know the
solution. If you comment out only the scanf("% d",&n); line, the problem
goes away. It appears that something is being left in the input buffer by
scanf. When getchar() goes looking there a few lines later, it sees
whatever is there and closes the program without waiting for a new entry.
fflush(stdin); before the getchar() clears the input buffer for you but it
doesn't work on my configuration.
By the way, the fflush(stdout); clears the output buffer and is there to
ensure that "Taper ENTREE pour continuer..." is sent to the screen.
Chuck
|