Author Topic: File passed by parameter not found.  (Read 4611 times)

Offline Fabricio

  • Single posting newcomer
  • *
  • Posts: 3
File passed by parameter not found.
« 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.
« Last Edit: May 27, 2011, 06:11:35 pm by Fabricio »
Sorry if bad english.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: File passed by parameter not found.
« Reply #1 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.

Offline Fabricio

  • Single posting newcomer
  • *
  • Posts: 3
Re: File passed by parameter not found.
« Reply #2 on: May 29, 2011, 01:54:51 am »
Thank you very much, jens!
Sorry if bad english.