Conversation started Sep 14, 2012 at 21:41.
Sep 14, 2012 21:41
Hey, Im using command line arguments for a program that takes a filename and reads from the location specified
If i open the program with the F5 button, and enter the name of a file that's there it works
But with command line arguments it doesnt work unless I enter the full file destinatoin
why?
With normal running it works with the name of the file

eg:"1.txt"
@MohamedAhmedNabil how are you providing the arguments?
@MohamedAhmedNabil can you show me the command you type?
Its a bit long but ill try
at first glance the code looks fine
Sep 14, 2012 21:45
"C:\Users\Mohamed\......\CWF 9.1.exe" 1.txt
this is the exact command
everytime i write 1.txt when i open it with CMD it says error
the program is called "CWF 9.1"?
yes
@MooingDuck I do write .exe btw. I forgot to write it here
@MohamedAhmedNabil I presume by "exact" you mean except for the "......" bit? :P
@MohamedAhmedNabil huh, looks fine to me
waaaaiiit
when you're in CMD, there's the bit you type at:
C:\Documents and Settings\Mohamed>
What does _that_ say?
Sep 14, 2012 21:48
I have to do this for it to work

"C:\Users\Mohamed\......\CWF 9.1.exe" "C:\Users\Mohamed\......\1.txt"
@MooingDuck C:\Users\Mohamed>
@MohamedAhmedNabil alright. The reason is says that, is that is the "current working directory" (CWD)
That is where it will look for all unqualified file names first.
type in the command "PATH"
and it will show you the rest of the places it looks for files.
@MooingDuck but when i go and press Start debugging i can type in "1.txt"
@MohamedAhmedNabil Visual Studio sets the CWD to the project folder when debugging.
each program has it's own CWD
@MooingDuck ooh. so the program opens with the CMD's CWD?
so either (A) have the program change the CWD, or (B) change the CWD before running the program
@MohamedAhmedNabil right.
Sep 14, 2012 21:51
@MooingDuck why?
@MohamedAhmedNabil historical reasons I think. Not sure. I think it used to be one CWD for the whole computer (DOS). CMD kinda sorta keeps that tradition.
@MooingDuck You said that i should have the program change the CWD. How can i do that?
msdn.microsoft.com/en-us/library/windows/desktop/… for details on setting the CWD on windows
if( !SetCurrentDirectory(argv[1]))
   {
      printf("SetCurrentDirectory failed (%d)\n", GetLastError());
      return;
   }
I've never done it, but it looks really straighforward :D
@MooingDuck C :/
@MohamedAhmedNabil C what?
Sep 14, 2012 21:54
@MooingDuck Hasnt C programming gone obsolete?
@MohamedAhmedNabil I wish :(
@MooingDuck btw, When are the Turing Award given?
@MohamedAhmedNabil The "turing test" is a theoretical test. There's many seperate actual tests.
@MooingDuck oh ok
Thanks for your help. Appreciate it :D
 
Conversation ended Sep 14, 2012 at 21:57.