Code: Select all
#include <stdio.h>
main()
{
int c;
c = getchar();
while (c != EOF)
{
c = getchar();
}
}
Code: Select all
#include <stdio.h>
main()
{
int c;
c = getchar();
while (c != EOF)
{
c = getchar();
}
}

hehe i'm pretty sure an EOF char has nothing to do with console input. EOF means end of file, and is generally used with reading files.XST1 wrote:I made a simple program to test EOF, yet I can't get it to function properly. Heres my code:
I can never get out of that while loop, even when I just hit enter (which should be EOF). Anyone know why it isn't working?Code: Select all
#include <stdio.h> main() { int c; c = getchar(); while (c != EOF) { c = getchar(); } }
Code: Select all
while ((int)c != 13) // Usually Enter
while(c != '\r' && c != '\n') // checking both CR/LF
Code: Select all