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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:52:48+00:00 2026-05-19T04:52:48+00:00

I make several calls to a function that reads data from an input file.

  • 0

I make several calls to a function that reads data from an input file. Everything works fine in debug mode, but when I try to run the executable from release mode, the line with fopen crashes the program after a few calls. My code is:
From header file:

#define presstankdatabase "presst_database.txt"

In function:

FILE *fidread;

fidread = fopen(presstankdatabase,"r");
if (fidread==NULL) {
    printf("Failed to open pressurant tank database: %s\n",presstankdatabase);
    return 1;
}

In debugging, I’ve inserted comment lines just before and just after the line starting with fidread =, and after several calls the program crashes and I get the message “A problem caused the program to stop working correctly. Please close the program.” The comment just before the fopen call is displayed, but the comment just after does not. My understanding of fopen is that is should return either a pointer or NULL, but it crashes before it even gets to the check. The only thing I can think of is that somehow I’m having memory problems, but I don’t know how that would fit in with fopen crashing. Does anyone know what might be going on? Thanks!

EDIT 1: I increased the size of three variables, and the only places they’re used (except in printf() calls), are as shown below.

char *constid = (char*)malloc(sizeof(char)*20);

Used like so:

strcpy(constid,"Propellant");
strcpy(constid,"Propellant tank");
strcpy(constid,"Pressurant tank");

If the variables are sized to 20, as shown above, it crashes. But if they’re larger (I’ve tried 120 and 100), the program runs. The variables aren’t used in any other places other than fprintf() or printf() calls.

  • 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-19T04:52:49+00:00Added an answer on May 19, 2026 at 4:52 am

    presstankdatabase should be a pointer to a string containing the filename to open. If fopen() crashes then that pointer is probably invalid (or NULL). Without any more code it is not possible to debug it further. Use the VC debugger to see what’s happening…

    EDIT:

    Another common cause of this is a filename string that suddenly stops being NULL-terminated.

    You should add a printf() call to print the filename before opening. It will most probably fail to produce the expected output. If not, then you have a more interesting form of memory corruption that will take some more work to weed out.

    EDIT 2:

    If the printf() call shows the correct string, then you probably have memory corruption somewhere else in your code that has mangled some internal structure of the C library. A common cause is going beyond the end (or the beginning for that matter) of a static array or a region provided by malloc().

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

Sidebar

Related Questions

I'm building a program that has several functions that need to read data from
I am making several calls to a function that initializes 2-d arrays of doubles.
I have an old Fortran77 program that calls a C++ function and passes several
Every time I make a project I develop several generic routines/modules/libraries that I expect
I've written several scripts that make use of the gdata API, and they all
I make a distributed embedded application that will make use of several micro-controllers. The
I have several strings that are being combined to make a URI. I want
I've used several modules to make EXEs for Python, but I'm not sure if
We make infrastructure services (data retrieval and storage) and small smart client applications (fancy
To make a JavaScript class with a public method I'd do something like: function

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.