Thread: how can my program tell how many bytes are remaining in a file?

  1. #1
    Registered User
    Join Date
    Nov 2011

    how can my program tell how many bytes are remaining in a file?

    while bytesremaining >=8 do something;
    if bytesremaing <8 then something else
    I am sorry but I am new and don't know how to code for this.

  2. #2
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    You shouldn't need to. The functions you're calling to read data from the file (fread, fgets, getc) will tell you whether there is no input left in the file. If you're reading chunks, each eight bytes long, then I suggest looking into fread.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
    You set size to 1, and nmemb to 8.
    You look at the return result to see how many bytes you actually read.
    You then do your if / else thing.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 19
    Last Post: 01-04-2013, 11:20 PM
  2. Replies: 2
    Last Post: 01-02-2013, 11:03 PM
  3. I need time remaining program?
    By shansajid in forum C Programming
    Replies: 7
    Last Post: 12-31-2012, 01:21 AM
  4. remaining input from getch()
    By PierreB in forum C Programming
    Replies: 6
    Last Post: 03-25-2004, 02:10 PM