EOF file pointer

This is a discussion on EOF file pointer within the C Programming forums, part of the General Programming Boards category; Hi, Id like to know if while Im reading a file I can check wether the next cycle in my ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    2

    EOF file pointer

    Hi,
    Id like to know if while Im reading a file I can check wether the next cycle in my While is going to be EOF... I need this because Im reading 13 byte chunck at a time. sorry for my english. thank you in advance.

    code:
    Code:
    while (ch=fgetc(fp))!=EOF)
                    //check the buffer
                    buffer++;
                    ....
                    if ((buffer<12) && (###)
    ### here I want to check if current position + 1 == EOF

    any answer is welcome

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    Well if you're reading from a file, you can start by using fseek() and ftell() to work out where the end of the file is.
    You can then count how many bytes you read, and thus work out whether you've reached the end or not.

    Or you could do
    Code:
    char buff[13];
    while ( fread( buff, 13, 1, fp ) == 1 ) {
      // do something with 13 bytes of data
    }
    If there is less than 13 bytes remaining at the end of the file, then fread() won't return them.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    2
    Thank you very much! Ill try that way.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM

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