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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:51:29+00:00 2026-06-01T11:51:29+00:00

I am using fread() in C++ to read very large binary files (100MB-2GB). The

  • 0

I am using fread() in C++ to read very large binary files (100MB-2GB). The binary files are originally written from C++ by outputting a series of “packets”. The packets are made of a “header” struct (that contains a size field) being directly written to a file, and then binary content with size equal to the size written in to the header. When reading the files, the packets are looped over, the header is read in to a struct and the content is read in to a void pointer of the size provided in the header.

This is a known working method already implemented in other tools (meaning I can validate the files I am trying to read). Assume all files we are working with are validated. In at least one file, my implementation of reading a binary file is working correctly.

However, with another file fread() starts acting funky for no apparent reason. After many successful reads, I cleanly read the header portion of a packet using:

if (sizeof(stHdr) != fread((void *)&stHdr, 1, sizeof(stHdr), fi))

By cleanly reads, I mean fread() returns “sizeof(stHdr)” as expected, and feof(fi) and ferror(fi) both return 0. However… stHdr is completely filled with all zeros; the value of every field in stHdr contains 0x0. I have validated the binary file to be correctly formed, and to have data at the point that I am reading.

Has anyone seen this before or know what could be causing it?

Thanks!

  • 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-06-01T11:51:31+00:00Added an answer on June 1, 2026 at 11:51 am

    The problem ended up being a classic case of PEBKAC…

    Apparently my binary file did become corrupted at some point and actually did have a bunch of 0s in it. I had copied it directly out of a repository and the file was validated before being put in to the repo, so I assumed it was good. Apparently something bad happened to my local version of the file and was the source of my problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

when I read from a file using fread (C language), the return value of
I want to read pcm samples from a file using fread and want to
I am using fread to read a large chunk of image data (> 1
I am using fopen() and fread() to read files if( file_exists( $file ) ){
When using a synchronous I/O such as fread which is buffered, the read operations
I am using open/read functions, there's feof for fopen/fread to detect end-of-file, what's the
Right now I am using fread() to read a file, but in other language
Using PHP's proc_open() , I can start a process, read from STDOUT and STDERR
i am using a Unix machine and i am trying to read from console
I'm trying to read use fread to read in values from an external file

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.