User forums > Using Code::Blocks
File passed by parameter not found.
(1/1)
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.
--- 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
{
}
}
--- End code ---
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:
Thank you very much, jens!
Navigation
[0] Message Index
Go to full version