Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.
argc and argv are used when you are starting a program from the command line, or want to pass some variables to the program. (Dates back a bit!)
argc contains the number of arguments and argv is an array of pointers to the arguments which are strings. EG: char *argv[];
The first argument is always the programs name.
For example, if you had a program called 'squareroot'. You could call it by:
squareroot 4
squareroot would have 2 in argc and two pointers, one to "squareroot" and one to "4"
and it would return 2, (we hope!)
That is why main is declared as
int main(int argc, char *argv[]);
the return value is used by the calling program to see if the called program was ok.
There is another command line argument that sets enviroment variables, but that is only used by the real geeks and hackers.
Argc is the number of arguments. Argv is an array (vector) holding pointers to the string arguments passed on the command line. There will be the same number of strings as argc indicates and can be accessed as argv[n], where n is a number between 1 and argc. argv[0] is treated special, in that it will contain the name of the program itself.
example:
for (int n = 1; n < argc ; n++)
if (strncmp(argv[n],"magicword")==0)
doSomethingSpecial();
In C language there are no "argc" and "argv" reserved words. This come from examples from the books.
The guys before correctly explained those examples, but you could name them as follow:
int main(int count, char *garbage[])
{
}
and you will not find argc and argv in the code at all
or if you don't have parameters to you program then
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.