Thread: Help plssssssss!!!!!!!!

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    5

    Help plssssssss!!!!!!!!

    I am about writing a program which will read a [/B]Binary File[/B] then stored every 4 bytes in [/B]unsigned long variable[/B].
    Assum binary file like:
    0000000: 23 4f 9d ce 00 0f fa.........
    What I did was, i used:

    FILE* Inputfile = fopen("Binary.b", "rb")

    But I couldn't work out how to store it in unsigned long variable!!!
    Any help from you guys would be greate appreciate
    Last edited by Chook; 09-10-2003 at 01:29 AM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    union data
    {
       unsigned char bytes[4]; 
       unsigned long int var;
    } here;
    
    fread( &here.bytes, sizeof( unsigned char ), 4, fp );
    Enjoy.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Actually, I think your answer is simpler than that.
    Code:
    unsigned long int var;
    FILE* Inputfile;
    
    ...
    
    Inputfile = fopen("Binary.b", "rb");
    fread( &var, sizeof(var), 1, Inputfile);
    Check for errors...
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed