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 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 is treated special, in that it will contain the name of the program itself.
for (int n = 1; n < argc ; n++)