Like Tree1Likes
  • 1 Post By Salem

how do I increment a file pointer by eight bytes exactly?

This is a discussion on how do I increment a file pointer by eight bytes exactly? within the C Programming forums, part of the General Programming Boards category; I am trying to write a program that will read eight bytes from a file, perform some math on it ...

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    27

    how do I increment a file pointer by eight bytes exactly?

    I am trying to write a program that will read eight bytes from a file, perform some math on it and then read in eight more bytes untill there is nothing left to read even if the last group is < 8 bytes. Do I need an array?
    Thanks
    Last edited by Once-ler2; 01-14-2013 at 12:55 PM.

  2. #2
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    506
    Lookup the fread() function, it does exactly what you need.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,762
    Look up fread()

    size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);

    If you pass 8,1 as the middle 2 parameters, you'll either read 8 bytes or nothing, and the result will be either 1 or 0.

    If you pass 1,8 as the middle 2 parameters, you'll read 8 bytes at most, but you might read anything from 0 to 7 as you get to the end of the file.
    stahta01 likes this.
    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.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,531
    Using an array is one option. It is not the only option, nor is it mandatory. That all depends on what the "math" entails, and anything else your code is trying to achieve.

    Your thread title has nothing to do with the question either. Reading data from a file and incrementing a file pointer are not necessarily related concepts.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy in reply to you, it is likely you deserve it. Suck it up, sunshine, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Does fflush increment file pointer??
    By juice in forum C Programming
    Replies: 9
    Last Post: 12-28-2011, 09:32 PM
  2. Got Error in Pointer increment. Help !!!
    By mysql2779 in forum C Programming
    Replies: 9
    Last Post: 03-19-2011, 03:10 AM
  3. Increment a pointer variable
    By skiabox in forum C Programming
    Replies: 5
    Last Post: 11-17-2010, 11:24 AM
  4. pointer increment error
    By WDT in forum C++ Programming
    Replies: 7
    Last Post: 12-09-2007, 08:01 AM
  5. Increment the address stored in a pointer???
    By patricio2626 in forum C++ Programming
    Replies: 9
    Last Post: 04-04-2007, 07:36 PM

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