Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

cMADsc

need help with (int argc, char *argv[])

This topic is 6313 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Greetings all, I need assistance on using argc, argv. I have books with them in it but they don''t describe the concept behind them. Any help is appreciated. Thanks. ----------------------------- "There are ones that say they can and there are those who actually do." "...u can not learn programming in a class, you have to learn it on your own."

Share this post


Link to post
Share on other sites
Advertisement
These are used for programs that are run from the comand line. Each argument can take a value which can be used withing the program. (like those old dos programs) they can also be used when running the program from withing another program. (i think)

HHSDrum@yahoo.com

Share this post


Link to post
Share on other sites
argc is the number of command line arguements passed to your program. argv are the actual arguements.

Here''s an example

  

#include <iostream>
#include <stdio.h>

int main(int argc, char *argv[])
{
std::cout << argc << std::endl;

for(int i=0;i<argc;i++)
{
std::cout << argv[i] << std::endl;
}

return 0;
}


in the console or terminal

>D:\test\Debug>test i am a beautiful butterfly
6
D:\TEST\DEBUG\TEST.EXE
i
am
a
beautiful
butterfly


argv[0] is the program itself, so your args start at 1.

Share this post


Link to post
Share on other sites
void main(int argc, char *argv[])
{
if (argc == 1)
{
printf("usage: bla.exe ");
return;
}
if (argc == 2)
{
// do something with argv[1],
// argv[0] is your executable file name
}
else
{
printf("too many arguments");
return;
}
}

pretty easy
you get the string parsed already which make it easier

Arkon
[QSoft Systems]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!