Reputation: 183
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.
Upvotes: 3
Views: 2371
Reputation: 57784
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'
Upvotes: 1
Reputation: 14450
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.
Upvotes: 0
Reputation: 50313
Has your file path spaces? If so, you need to enclose it in quotes.
Upvotes: 4