Re: [Dev-C++] Basic C question: scanf
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Nurhidayat <dh...@ma...> - 2001-07-12 06:06:12
|
At 20:47 11/07/2001 -0700, you wrote:
>When the program is run, the prompt "Enter salaries:" is printed. After
>that, I enter a series of numbers, then press the Enter key. The printf in
>the loop is executed for each number input, but then the program hangs.
No, it doesn't hang.
After the printf in the loop is executed, scanf still waiting legal input.
while (scanf("%lf", &salary) == 1) {
...
}
So to finish scanf, you have to give illegal input or non numeric
character, like 'x' (or another alphabet character you like) then press
[Enter].
Try to give input like this:
Enter salaries: 100 200 150 600 x [Enter]
If you write loop like this
while (scanf("%lf", &salary) != EOF) {
...
}
You can use <ctrl>Z to finish input.
___Nurhidayat___
|