Reading in bits from a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DarkArchon
    New Member
    • Mar 2008
    • 11

    Reading in bits from a file

    I'm having a bit of trouble of reading in 32 bit chunks from a file and then storing it into an integer, and then repeating the process for the entire file. Is there an easier way to do this rather than bit by bit?
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by DarkArchon
    I'm having a bit of trouble of reading in 32 bit chunks from a file and then storing it into an integer, and then repeating the process for the entire file. Is there an easier way to do this rather than bit by bit?

    If you read from a file then you are reading a byte and 1 character in a file is 1 byte.

    Raghuram

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      What if your file format?

      Can you use binary read?

      If so, you can read into an array of int of any size with one read.

      Comment

      • DarkArchon
        New Member
        • Mar 2008
        • 11

        #4
        The file is a binary file. And yes ideally I'd read in the file and put it into a unsigned int array. I know in C++ you can use the fstream to get binary files, but what do you use for C?

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          C uses a FILE*.

          BTW: Dig deep enough into C++ streams and you will find the FILE*.

          You should be able to fread() to an address for a number of bytes.

          Comment

          Working...