Re: HELP!! Two questions from <<the c programming language>>



Ian Collins <ian-news@xxxxxxxxxxx> writes:
Tak wrote:
[...]
{
char c;

while ((c = getchar()) != EOF)
[snip]
I don't know whether it's right or not?

It looks OK, but have you tried it? It should be easy enough to test.

What type does getchar() return?

See also section 12 of the comp.lang.c FAQ, <http://www.c-faq.com/>.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages

  • Re: Menu looping
    ... EOF is not a char. ... EOF is guaranteed to have a negative value of type int ... condition can be true *either* if getchar() returns EOF (and EOF is ...
    (comp.lang.c)
  • Re: getchar() problem
    ... int main ... Consider signed chars and a char with value less than EOF;-) ... getchar() returns either EOF or the character "as an unsigned char ...
    (comp.lang.c)
  • Re: Problem about type promotion and equality operator.
    ... One paragraph of the item writes:"If type char is unsigned, ... EOF value will be truncated (by having its higher-order bits discarded, ... result type detemined by the usual arithmetic conversions are equal." ... The EOF truncated value is the one returned by getchar(). ...
    (comp.lang.c)
  • Re: getchar() problem
    ... int main ... Consider signed chars and a char with value less than EOF;-) ... getchar() returns either EOF or the character "as an unsigned char ...
    (comp.lang.c)
  • (part 44) Han from China answers your C questions
    ... char* GetChar() ... In your original program, the storage goes away. ... This is so people can easily killfile ...
    (comp.lang.c)