Thread: reading binary files

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    88

    reading binary files

    I am confused on how to read in a certain amount of bytes at a time as hex numbers from a binary file.
    I want to open a binary file and read the first 4 bytes. can anyone give me an example of how to do this after the file is opened.

  2. #2
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    You should take a look at the fread() function. I think that will do what you need.

    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    88
    alright, once I have read in these bytes. How can I compare it to see if it is the right 4 bytes

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading a file in binary question
    By Dan17 in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 12:28 AM
  2. Reading Binary files
    By earth_angel in forum C++ Programming
    Replies: 10
    Last Post: 07-12-2005, 06:48 AM
  3. Reading data from a binary file
    By John22 in forum C Programming
    Replies: 7
    Last Post: 12-06-2002, 02:00 PM
  4. problem reading files in C
    By angelfly in forum C Programming
    Replies: 9
    Last Post: 10-10-2001, 11:58 AM
  5. Need Advice in reading files
    By jon in forum C Programming
    Replies: 4
    Last Post: 10-07-2001, 07:27 AM