views:

61

answers:

3

I'm trying to add my file in Visual Studio as command line parameters. I know my code works since when I use fopen("whole path here", "r"), it runs. I then add the file as a command line parameter instead, and I get no such file or directory. Any thoughts? Thanks.

+1  A: 

Has your file path spaces? If so, you need to enclose it in quotes.

Konamiman
A: 

You can always debug in Visual Studio what file name you are getting from the command line, and then you have an idea of what's wrong.

Priyank Bolia
Are you supposed to put quotes in either the Command Line Parameters in Visual Studio or fopen? e.g. fopen(argv[1], "r")
jet
you have to put quotes in the Command Line Parameters in Visual Studio
Priyank Bolia
A: 

Are you sure the command line parameter is handled correctly? Temporarily replace your main() with this:

int
main (int argc, char **argv)
{
    int j;
    for (j = 0;  j < argc;  ++j)
        printf ("argv [%d] = '%s'\n", j, argv [j]);
    return 0;
}

My guess is that you have file paths with spaces in them. Those have to be quoted on the command line:

C:\> myprogram "c:\Documents and Settings\Administrator\My Documents\Test.dat"

If this were unquoted, the test program would output:

argv [0] = 'myprogram.exe'
argv [1] = 'c:\Documents'
argv [2] = 'and'
argv [3] = 'Settings\Administrator\My'
argv [4] = 'Documents\Test.dat'
wallyk