RE: [Dev-C++] Basic C question: scanf
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Luigi S. <gi...@li...> - 2001-07-13 22:41:09
|
In my opinion you should use the solution suggested by Nurhidayat (I mean
compare the value returned by scanf with EOF, see below), in fact this
allows your code be used like a "filter".
Just in case you are not familiar with redirection and pipes, here is what
I mean.
Suppose you wish to input these values: 100 200 300
You could feed the values via console (as you usually do) or by the
following two steps: (I assume that you are in a DOS box, and your
executable is named salary.exe)
- write the values in a text file (say that you name the file: salary.dat)
- launch the command: salary < salary.dat.
try also: salary < salary.dat > out.dat
and : salary < salary.dat >> out.dat
The above is redirection.
Better yet: if the values to be fed to salary.exe are the output of another
executable (say it: compute.exe), assuming that it writes to stdout, you
could tie the output of "compute" to the input of "salary" by the following
command:
compute | salary
The above is an example of a "pipe".
Hope this was of some help.
At 22.43 12/07/01 -0700, you wrote:
>Thanks to everyone who replied. I had expected the <cr> to be a legal input.
>Thanks for the info.
>
>Mary
>
>
>
>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
>
>
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
---
gisan
|