Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7411061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:19:42+00:00 2026-05-29T06:19:42+00:00

I have a file that I read into a char array. The char array

  • 0

I have a file that I read into a char array.

The char array now holds a certain number of bytes, now if I know the file stored a 32bit integer in little endian at position say 0x8, how do I retrieve it from the char array?

FILE * file = fopen("file");
char buffer[size];
fread(buffer,1,size,file);
int = buffer[0x8]; // What should I do here?
// I imagine it involves some strange pointer
// arithmetic but I can't see what I should do,
// casting to int just takes the first byte,
// casting to (int *) doesn't compile
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:19:42+00:00Added an answer on May 29, 2026 at 6:19 am

    you need to cast it like so:

    int foo = *((int *) &buffer[0x8]);
    

    Which will first cast the spot to a int pointer and the dereference it to the int itself.

    [watch out for byte-ordering across different machine types though; some do high bytes first some do low]

    And just to make sure the example is well understood, here’s some code showing the results:

    #include <stdio.h>
    
    main() {
        char buffer[14] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13 };
        int foo = *((int *) &buffer[0x8]);
        int bar = (int) buffer[0x8];
    
        printf("raw: %d\n", buffer[8]);
        printf("foo: %d\n", foo);
        printf("bar: %d\n", bar);
    }
    

    And the results from running it:

    raw: 8
    foo: 185207048
    bar: 8
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string stored in a file that is read into a string.
I have binary data in a file that I can read into a byte
I have a small text file that I'd like to read into a scalar
I have read an xml file into a char [] and am trying to
I have a config file that I read using the RawConfigParser in the standard
I have to write a program that read from a file that contains the
I have a file that I want to read in using the File::Slurp module
I have some configuration data in a config file that I read off disk
I have a text file. I want read that file. But In that if
I have an INI file that I want to read the line DeviceName=PHJ01444-MC35 from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.