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

  • Home
  • SEARCH
  • 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 171251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:57:17+00:00 2026-05-11T12:57:17+00:00

While reading a binary file using DJGPP on DOS this code hangs. This happens

  • 0

While reading a binary file using DJGPP on DOS this code hangs. This happens when the fread call is made. If the call is removed then the program runs successfully. The same code runs fine through Visual C++ 2008. Has anyone experienced similar issues with djgpp ? Am I missing out on something really simple ?

char x;  string Filename = 'my.bin' ;  fp = fopen(Filename.c_str(),'rb');   if (fp == NULL) {     cout << 'File not found' << endl ;  }  if (fseek (fp, 0, SEEK_END) != 0) {     cout <<'End of File can't be seeked';      return -1;  }  if ( (fileLength = ftell(fp)) == -1) {     cout <<'Can't read current position of file';      return -1;  }  if (fseek (fp, 0, SEEK_SET) != 0) {     cout <<'Beginning of File can't be seeked';      return -1;  }   if (fread(&x,sizeof(x),1,fp) != sizeof(x)) {     cout <<'file not read correctly';      return -1;  } 
  • 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. 2026-05-11T12:57:18+00:00Added an answer on May 11, 2026 at 12:57 pm
    • I don’t see what ‘fp’ is. I just have to assume it’s ‘FILE * fp;’.

    • I don’t see that you actually include < stdio.h >, and have to assume you do.

    • I don’t see that you actually include < iostream > and declare ‘using namespace std;’, and have to assume you do.

    • I don’t see what comes after the fread() call that could tell you if call succeeded.

    Going through the process of actually reducing your faulty code to the absolute but complete minimum to reproduce the error is the first thing you should do when a piece of code has you dumbfounded.

    It might (and usually does) turn out that the problem isn’t even where you thought it is.

    That being said, I’d try replacing

    if (fread(&x,sizeof(x),1,fp) != sizeof(x)) {     cout <<'file not read correctly';      return -1;  } 

    with

    int i; if ( ( i = fgetc( fp ) ) == EOF ) {     perror( 'File not read correctly' );     return -1; } x = (char) i; cout << 'Success, read '' << x << ''.' << endl; 

    Using ‘perror()’ instead of homebrewn cout messages gives you additional information on the cause of any error. Using ‘fgetc()’ will show you that the file actually does contain what you think it does, and that your problems are not due to the somewhat uncommon use of fread() for a single byte.

    Then report back.

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

Sidebar

Ask A Question

Stats

  • Questions 91k
  • Answers 91k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You may install different JDKs easily: just specify different folders.… May 11, 2026 at 6:19 pm
  • Editorial Team
    Editorial Team added an answer If I've understood your question right replacing $checkboxes = $_POST['checkboxes'];… May 11, 2026 at 6:19 pm
  • Editorial Team
    Editorial Team added an answer I would use HDLC. I have had good luck with… May 11, 2026 at 6:19 pm

Related Questions

I'm writing an editor for large archive files (see below) of 4GB+, in native&managed
I have a set of classes I wish to serialize the data from. There
In an Open Source program I wrote , I'm reading binary data (written by
I am inputting a 200mb file in my application and due to a very

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.