Welcome to EDAboard.com

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.

What's the meaning of 'argc' and 'argv' in C Language?

Status
Not open for further replies.

elec-eng

Full Member level 5
Joined
Nov 16, 2006
Messages
243
Helped
20
Reputation
40
Reaction score
5
Trophy points
1,298
Activity points
2,926
Please help me

i cant understand the meaning of 'argc' and 'argv' in the C Language

and what are there functions

thank
 

btbass

Advanced Member level 5
Joined
Jul 20, 2001
Messages
1,897
Helped
438
Reputation
880
Reaction score
287
Trophy points
1,363
Location
Oberon
Activity points
12,861
C Language help

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.
 

slcoleman

Newbie level 3
Joined
Aug 17, 2007
Messages
3
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,310
C Language help

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();
 

dsp4us

Member level 2
Joined
Jan 21, 2003
Messages
48
Helped
10
Reputation
20
Reaction score
3
Trophy points
1,288
Activity points
373
C Language help

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

int main()
{
}
 

tjr

Member level 3
Joined
Mar 2, 2006
Messages
60
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,674
Re: C Language help

argc and argv r useful to pass arguments at command prompt.

argc - it is counter to store how many arguments u r passing.
argv - is a 2D string array to store arguments.

there r not reserved words, u can choose ur own terms.
 

jayavardhan

Full Member level 2
Joined
Sep 1, 2006
Messages
126
Helped
3
Reputation
6
Reaction score
0
Trophy points
1,296
Location
India
Activity points
1,851
C Language help

argc contains the number of arguments and argv is an array of pointers to the arguments which are strings.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top