Thread: Noob: needs help with file I/O

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    2

    Noob: needs help with file I/O

    Hi all,

    I'm having a prob with loading a file into an array.

    I'm fine with opening the file but when it come to the fread command i seem to be failing as the document size will be variable, so how can i state a file size as "num_of_elements".

    if this is not clear, then my basic idea is:

    i want to open a file in 128 bit chunks and load it into an array so i can perform function on the array. Thats about it.

    I would provide code, but i've butchered it that much it aint much use.

    any help would be greatly appreciated.

    cheers.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Code:
    char buff[128];
    while ( fread ( buff, sizeof buff, 1, in ) == 1 ) {
      // got a 128 byte buff
    }
    Did you remember to open the file in binary mode?

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    2
    cheers for the reply,

    yeah I have opened the file using the identifiers "rb" so should be operating in binary mode.

    Will take a look at implementing the code when i get chance.

    Many thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. File I/O Assertion Failure in VS2008
    By clegs in forum C Programming
    Replies: 5
    Last Post: 12-25-2008, 04:47 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. 2 questions surrounding an I/O file
    By Guti14 in forum C Programming
    Replies: 2
    Last Post: 08-30-2004, 11:21 PM
  5. advice on file i/o
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-29-2001, 05:56 AM