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 7543645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:28:52+00:00 2026-05-30T08:28:52+00:00

Having a binary file that holds: # hexdump file.pak 0000000 09 00 00 00

  • 0

Having a binary file that holds:

# hexdump file.pak 
0000000 09 00 00 00 
0000004

trying to read it with fread results in :

int main(void){
  char *filename = "file";
  FILE *fh = header_open(filename);
  header_init(fh);
  header_read_num_files(fh);
  header_close(fh);
}

FILE *header_open(char *pkg_file){
  FILE *fh;
  // open file with binary/read mode                                                                                                                                               
  if ( (fh = fopen(pkg_file, "ab")) == NULL){
    perror("fopen");
    return NULL; // todo: ...                                                                                                                                                      
  }

  return fh;
}

int header_read_num_files(FILE *fh){
  fseek(fh, 0L, SEEK_SET);
  char c;
  fread(&c, sizeof(char), 1, fh);
  fprintf(stderr,"buff received: %d\n", c);
}

/* write first 0 for number of files */
void header_init(FILE *fh){
  unsigned int x= 9;
  fseek(fh, 0, SEEK_SET);
  fwrite( (const void*)&x, sizeof(int), 1, fh);
}


output: buff received: 112

My system uses the small-endianness conversion. but still the other bytes are set to zero, I cannot really see why I’m getting this output.

An explanation is much appreciated.

  • 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-30T08:28:53+00:00Added an answer on May 30, 2026 at 8:28 am

    You open the file with “ab” option. Bur this option does not allow to read from file, only writing to its end is alloowed. Try to open this way

    fh = fopen(pkg_file, "w+b")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having following issue with reading binary file in C. I have read
I'm trying to read a binary file (which represents a matrix in Matlab) in
I have a C++ program that will read in data from a binary file
I'm having some trouble with replacing a portion of a file in binary mode.
I use this code fragment to read a binary file into a array fid=fopen('data.bin','rb')
I'm trying to figure out how to update the data in a binary file
Quick summary: I'm making an application that parses a binary file, stores vertices and
I think I am having trouble with binary file io. If I run my
I am having problems appending data to a binary file. When i seek() to
I have a file that has both ASCII text and binary content. I would

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.