News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

File passed by parameter not found.

Started by Fabricio, May 27, 2011, 05:51:48 PM

Previous topic - Next topic

Fabricio

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.

#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.

Jenna

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.

Fabricio