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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:34:01+00:00 2026-06-15T23:34:01+00:00

im facing a bit of a problem recently. i want to implement my own

  • 0

im facing a bit of a problem recently. i want to implement my own fopen function for error checking purposes.

Heres the relevant code so far:

enum _Errorcode_ openFile( const char * c_str_filename, const char * c_str_mode, FILE* the_file )
{
    the_file = fopen( c_str_filename, c_str_mode );

    if( the_file == NULL )
    {
        return FILE_IO_ERROR;
    }

    else
    {
        return OK;
    }
}

i call the function like this:

FILE * oFile = NULL;
...
ErrorCode = openFile( "myfile.txt", "r", oFile );

If i check the pointer addr of oFile afterwards, its still pointing to NULL.
The wird thing is, my function returend OK, and no failure. why is that so?

The file exists, if i call the fopen() function just so, everything works.

  • 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-15T23:34:03+00:00Added an answer on June 15, 2026 at 11:34 pm

    C passes parameters by value, so you assign to a copy of oFile, that’s why you don’t see the change outside of openFile().

    Pass a pointer to it, like so:

    enum _Errorcode_ openFile( const char * c_str_filename, const char * c_str_mode, FILE** the_file )
    {
      *the_file = fopen( c_str_filename, c_str_mode );
    
      if( *the_file == NULL )
      {
        return FILE_IO_ERROR;
      }
      else
      {
        return OK;
      } 
    }
    ....
    FILE * oFile = NULL;
    ...
    ErrorCode = openFile( "myfile.txt", "r", &oFile );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam facing problem in understanding and converting a matlab code into opencv. I want
iam facing problem in passing array to view. this is my controller code.. function
upfront the code to visualize a bit the problem I am facing: This is
I was facing this unique problem of generating a bit-mask based on the input
I'm facing a rather queer problem. I use an Ubuntu(Lucid Lynx-64 bit, to be
I'm facing a bit of an odd problem here. I just launched: http://claudiu.phpfogapp.com/ To
Recently I am the facing problem with Apache Tomcat 6.0.35 on Linux Centos. I
I am facing problem with debugging my 64 bit application thru a project of
I am new to java development ! Facing some problem , and bit confused.
I'm facing a problem while converting ms sql function into mysql. Here is ms

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.