RE: [Dev-C++] problem with stdin and stdout
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ya...> - 2002-01-03 14:57:06
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Luigi Santillo
> Sent: Wednesday, January 02, 2002 5:59 PM
> To: dev...@li...
> Subject: [Dev-C++] problem with stdin and stdout
>
>
> Hello list
>
> I tried to make a simple program that prints the amount of
> characters found
> in a file. Here is my code:
>
> count.c
> ------
> #include <stdio.h>
>
> int
> main()
> {
> int n = 0;
>
> while (getchar() != EOF)
> n++;
>
> printf("n = %d\n", n);
>
> return 0;
> }
> ---------
>
>
> One could use the program in one of these 4 ways:
> 1) count get input from stdin and print amount
> of character to
> stdout
> 2) count < foo get input from file "foo" (using
> redirection) print
> to stdout
> 3) count > bar get input from stdin, print output to file "bar"
> 4) count < foo > bar get input from "foo", print output to "bar"
>
> IMHO the above 4 commands are equivalent (to the extent that one
> types what is contained in the file "foo", when the input
> comes "directly"
> from stdin), so I expected the code to behave in the same way
> independent
> of the command I used; here are my results: say that the file
> "foo" is the
> following (an '@' stands for EOF):
>
> foo
> -----
> aa@
> -----
>
> When I try command #2 and #4 I get the correct answer: that
> is "n = 2". When I try command #3 (and manually type
> "aa+CTRL-z" on stdin) I find that
> "bar" is
>
> bar
> ------
> n = 2
> ------
>
> Strange enough when I use command #1 (and manually type
> "aa+CTRL-z" on
> stdin) I see nothing displayed!
Nothing is displayed to me too when using MINGW32. However when i sue
the BC++ 5.5 compiler the thing works correctly:
C:\c>temp
aa^Z
n = 2
So it is probably a compiler defect.
>
> I have tried the above with MinGW 2.95 on a Win98SE system. I
> think the
> problem is related to Windows, because I remember asking a
> similar question
> to Mr. Vranos and he answered me that he had no problem, he
> was using MinGW
> 2.95 too, but his system was running a different version of
> Windows (I'm
> not sure which one).
Yes i remeber you had asked something like that (i don't remember what
exactly) but i do not remember the answer i gave to you. Anyway i think
we have to do with compiler defect(s) and i do not think it has to do
with the operating system (this ctrl-z thing).
My OS is Win2k.
>
> I would appreciate if someone, running Windows 98SE, could
> try the above
> using my same compiler (it is the one shipped with Dev-C++
> 4.0 and I think,
> but am not sure, Dev-C++ 4.1) and let me know what happens:
> at least I
> would make sure that the problem is related to my
> installation of Windows.
No, it is the compiler.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.f2s.com
* Alternative URL: http://run.to/noicys
|