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

This is a discussion on how can my program tell how many bytes are remaining in a file? within the C Programming forums, part of the General Programming Boards category; while bytesremaining >=8 do something; if bytesremaing <8 then something else I am sorry but I am new and don't ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    150

    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.
    Thanks

  2. #2
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,541
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

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

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