Skip to main content
gamedev.net
🔒 Locked

DOS app - command line?

Started by peter86 8 replies 500+ views
Original Post
peter86
peter86
How do I catch the command line in a DOS app?
JuNC
JuNC
int main(int argc,char** argv)


argc is the count of (space separated) arguments and argv is an array of strings actually containing them.
peter86
peter86
I dosen´t work to me. How do I display the string with printf()? Output is always "9" to me.

[edited by - peter86 on December 30, 2002 11:47:30 AM]
peter86
peter86
int main(int argc, char* argv)
{
printf( argc );
}
cgoat
cgoat
That''s working right, argc is the count.

Try this:


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

return 0;
}
peter86
peter86
quote:
Original post by cgoat
That''s working right, argc is the count.



Of course I meant argv, just wrote wrong . Your code dosen´t work either, it just crashes.
Evil Bill
Evil Bill
cgoats code is correct.

What do you mean it crashes? What error message / code? Does it display anything, or just crash before printing anything?

Have you tried debbuging it to see more prescisely what causes the crash?

Member of the Unban Mindwipe Society (UMWS)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.