Thread: Hexadecimal read of a file

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    1

    Hexadecimal read of a file

    Well my English isn't too good so I'm not sure if I can explain this properly, hope you'll understand.
    What I want is to read a certain adress of an opened file's hexadecimal code (in order to read its signature and detect the file type)...now is there any way to do this and how?
    Thanks in advance

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Use fopen() to open the file in binary mode ("rb")
    Use fseek() to goto the offset in the file which interests you
    Use fread() to read as many bytes of the signature you want to
    Use memcmp() to compare that signature with what you expect to find.
    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. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 10:47 AM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM