how to pass the command line arguments in c
command line arguments
Collapse
X
-
Tags: None
-
U shuld do this using argc and argv.Originally posted by maddy dcostahow to pass the command line arguments in c
u will get a clear idea about this if u study any C book.
Raghuram -
need of command line arguments
hello.....
I am little bit confused with the implementation of command line argument. Actually i want to know why they have invented this feature... Is there is any real reason to implement this... There r other handy features available why they gone with it........... This is not dealing with any C,C++ or unix... I want to know generally...... .....
Plaese help me guys...........Comment
-
On C, you can pass command line using something like this:
on argc are strored the amount of argmuments of the program, and on argv[], the pointers to the strings that are the arguments. By deafult, the name of the program is recibed in the first place like an argument, and the array of pointers to the arguments is finished by a NULL.Code:int main(int argc, char * argv[]) { int i; printf("The arguments of %s are %d, and they are:\n",argv[0],argc-1); for (i = 0 ; argv[i] != NULL ; i++ ) printf("%d: %s\n",i,argv[i]); return 0; }
you can use pepe and jose instead of argc and argv, they are used with that name just by convention.
Try to compile it and you will see.
Yours,
DarkArtanisComment
-
You obviously are a post-unix person. Compare those command line argumentsOriginally posted by maddy dcostahello.....
I am little bit confused with the implementation of command line argument. Actually i want to know why they have invented this feature... Is there is any real reason to implement this... There r other handy features available why they gone with it........... This is not dealing with any C,C++ or unix... I want to know generally...... .....
Plaese help me guys...........
and the command itself as the parameters to a function and the function.
Together with IO (and their redirection) and the piping of commands they are
the building blocks of zillions of useful applications and services all over the world.
GUIs are just there for human beings and human beings are proven unreliable
when it comes to consistency so we won't let them start a second process when
the first one has finished and we certainly don't trust them to carry over results
from one process to the other ;-)
kind regards,
JosComment
-
Some informations you can see here http://publications.gbdirect.co.uk/c...s_to_main.html
We use command line arguments for many reasons.One example is to pass the name of a file into the programm.As an example we type(in LInux) : [PHP]./progr scores.txt alive.txt[/PHP]
progr : is the name of the programm
scores.txt and alive.txt : are the two arguments we pass to the programm.In this example scores.txt and alive.txt are the names of two files we want to process
argc : is argument counter (bigger than 1)
argv : argument vector
argv[0] : is always the name of programm
for this reason argc must be bigger than 1
In this example:
argv[1] : is the scores.txt
arg[v2] : is the alive.txtComment
-
That was done in 1972. The smallest computer was the size of a two-car garage and only had a console.Originally posted by maddy dcostaI am little bit confused with the implementation of command line argument. Actually i want to know why they have invented this feature...
ANS continues to require console support.
Consoles had all but disappeared but there remains a cult following.Comment
Comment