Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Fabricio on May 27, 2011, 05:51:48 pm

Title: File passed by parameter not found.
Post by: Fabricio on May 27, 2011, 05:51:48 pm
Hi.

I set a programs' argument (MENU Project > Set programs' argument... ) and specified a file name (test.txt) for debug mode.

But when i try to open that file (yes, it exists in debug folder), i get a null value.

Code
#include <stdio.h>
#include <stdlib.h>

void read_source_file( char * filepath );

int main( int argc, char **argv )
{
    read_source_file( argv[1] );

    exit(EXIT_SUCCESS);
}


void read_source_file( char * filepath )
{
    FILE *f = fopen( filepath, "r" );

    if ( f == NULL )
    {
        printf("File not found [%s]!", filepath ); // OUTPUT: "File not found [test.txt]!"
    }
    else
    {

    }
}

Help?

PS: if i drag the file on my .exe it works. It just dont work using that IDE option.
Title: Re: File passed by parameter not found.
Post by: Jenna on May 27, 2011, 07:03:48 pm
You most lilely have to fix the execution working dir in the projects "Properties -> Build targets" for your targets.
The default is the projects root-directory and not the folder where the exe is located.
Title: Re: File passed by parameter not found.
Post by: Fabricio on May 29, 2011, 01:54:51 am
Thank you very much, jens!