Correct me where I am wrong.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robertcullen
    New Member
    • Aug 2010
    • 4

    #1

    Correct me where I am wrong.

    Dear all,
    correct me where I am wrong.



    EOF has no ASCII value.
    It is a C defined constant of type int,with value -1.

    consider the program

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

    // getch();
    return(0);
    }

    how this program will terminate??(wil l it?)
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    There have been several threads about this.

    The value of EOF is irrelevant. The value of EOF is EOF. That is, if you use EOF in your code then your program is guaranteed to work. If you don't, then all bets are off.

    EOF represents a value larger than any possible number of bytes in a file. That value is EOF. The fact that some compiler writer picked -1 is just interesting.

    Comment

    Working...