need help with (int argc, char *argv[])
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."
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
HHSDrum@yahoo.com
argc is the number of command line arguements passed to your program. argv are the actual arguements.
Here''s an example
argv[0] is the program itself, so your args start at 1.
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 butterfly6D:\TEST\DEBUG\TEST.EXEiamabeautifulbutterfly
argv[0] is the program itself, so your args start at 1.
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]
{
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement