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.
Has your file path spaces? If so, you need to enclose it in quotes.
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With