verify EOF

This is a discussion on verify EOF within the C Programming forums, part of the General Programming Boards category; hi please have a look at the following code. Code: #include<stdio.h> #include<conio.h> main () { int c; while((c=getchar()) !=EOF) putchar(c); ...

  1. #1
    template<typename T> threahdead's Avatar
    Join Date
    Sep 2002
    Posts
    214

    verify EOF

    hi

    please have a look at the following code.
    Code:
    #include<stdio.h>
    #include<conio.h>
    
    main ()
    {
    	int c;
    
       while((c=getchar()) !=EOF)
       	putchar(c);
       getch();
    }
    how do i verify that the expression getchar() !=EOF is zero or one?
    AND how do i print the value of EOF?

    threadhead

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >how do i verify that the expression getchar() !=EOF is zero or one?
    If putchar ( c ); executes then the expression is one. You can say something like this, though that would be a bit silly:
    Code:
    int chk_bool = ( ( c = getchar() ) != EOF );
    
    while ( chk_bool != 0 ) {
      putchar ( c );
      chk_bool = ( ( c = getchar() ) != EOF );
    }
    >how do i print the value of EOF?
    Code:
    #include <stdio.h>
    
    int main ( void )
    {
      printf ( "%d\n", EOF );
    
      return 0;
    }
    Though once again, there's little point in doing this.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. EOF Explanation Anybody?
    By blackcell in forum C Programming
    Replies: 1
    Last Post: 01-29-2008, 08:09 PM
  2. EOF or not EOF?
    By CornedBee in forum Linux Programming
    Replies: 2
    Last Post: 09-14-2007, 02:25 PM
  3. EOF messing up my input stream?
    By Decrypt in forum C++ Programming
    Replies: 4
    Last Post: 09-30-2005, 03:00 PM
  4. whats the deal with EOF really ???
    By gemini_shooter in forum C Programming
    Replies: 7
    Last Post: 03-06-2005, 03:04 PM
  5. files won't stop being read!!!
    By jverkoey in forum C++ Programming
    Replies: 15
    Last Post: 04-10-2003, 05:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21