RE: [Dev-C++] Basic C question: scanf
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Mary S. <ms...@in...> - 2001-07-13 15:28:04
|
Thanks to everyone who replied. I had expected the <cr> to be a legal input.
Thanks for the info.
Mary
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...]On Behalf Of
Nurhidayat
Sent: Wednesday, July 11, 2001 11:03 PM
To: dev...@li...
Subject: Re: [Dev-C++] Basic C question: scanf
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___
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|