vishnu said:
> 1. The logic of the program
> getchar () have been used here . whenever a cprogram starts three
> shandard files are opened named stdin , stdout , and stderr . if u dont
> specify any file as input to the program :
> c:\program.exe <file1.txt
The C Standard does not guarantee that this is the right way to specify
input from a file. Indeed, your command line shows severe signs of
non-portability. For example, it certainly doesn't work on my machine.
> then it will asuume stdin standard stream attached to the keyboard as
> its input and thus getchar gets it's input from stdin i.e. keyborad and
> simply outputs it till u enter end of file.
The C Standard does not guarantee that a keyboard is attached to the system.
Nor does it dictate which device is attached to stdin.
> u may rum the program in tow ways.
> c:\program.exe
This doesn't work on my machine. What makes you think it'll work on the OP's
machine?
> in this case stdin is taken as input stream attached to the program and
> program just prints whatever u type on the screen
> 2.as u have asked about EOF
> EOF is defined as
> #defined EOF -1
No, it's not. Firstly, the above is a syntax error. Secondly, the true
definition of EOF in language terms is: "a negative integral constant
expression that is returned by several functions to indicate end-of-file
,that is, no more input from a stream;"
So it might, or might not, be -1.
> it may have different value on your systems.
Right. So there wasn't much point in giving a value of -1, was there? Still,
full marks for pointing this out. We can, however, state categorically that
its value is /negative/.
> long nc;
>
>
> nc = 0;
> while(getchar() != EOF)
> ++nc;
> printf("%1d\n",nc); // I think it should be %ld in
> //in place of %1d
Please don't use // when you mean /* */
Yes, you are correct; it should be %ld rather than %1d ("ell" rather than
"one") - better still would be to change nc to unsigned long and use %lu.
> and there is no need for long , simple int will work since
You cannot guarantee that.
> EOF value may be out of range of charectyers and also getchar() outputs
> an integer type u may have used int in place of long nc;
You have misunderstood the reason long int was used. It is not storing the
result of getchar(). It is being used as a counter.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)