getchar()

Marc WANDSCHNEIDER storm at cs.mcgill.ca
Tue Mar 5 16:36:44 AEST 1991


The following file:

#include "stdio.h"
main()
{
   int c;
   c = getchar();
   while (c != 65) {     /* 65 is capital A on the PC*/
       putchar(c);
       c = getchar();
     }
}

   Echos every character that you put on the screen.  However, it does not 
stop (even after a Capital A) until you hit return.

   I changed the program to this:

#include ....
main()
{
    long nc;
    nc = 0;
    while(getchar() !=65)
                ++nc;
    printf("%ld\n", nc);
}

   This program STILL echos the characters I type in (even without the 
putchar()), and will only abort after I've hit the RETURN AFTER a "A".

    Can somebody offer some insight into what the hell is going on...?

    Also, is there and EOF character on the PC.  The origional program for
both the above cases was !=EOF, but I changed it to !=65....

    Any help would be great.

    Thanks.

./*-

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
storm at cs.mcgill.ca         McGill University           It's 11pm, do YOU
Marc Wandschneider         Montreal, CANADA            know what time it is?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the Comp.lang.c mailing list