How to access command-line arguments?

Answers were Sorted based on User's Feedback



How to access command-line arguments?..

Answer / hello

int main(int argc, char * argv[])
{
//argc has count of no of arguments on command line.
// argv[] contains array of strings seperated by space.
// so argv[1] will give u, second argument, with first
// argument being ur ./a.out(in unix)/test.exe(in win)
// so this way u can access CL args.

// ur code.
}

Is This Answer Correct ?    6 Yes 0 No

How to access command-line arguments?..

Answer / rakesh

int main(int argc,char *argv[])
{
int i;
for(i=0;i<argc;i++)
cout<<argv[i];
}

Is This Answer Correct ?    4 Yes 0 No

How to access command-line arguments?..

Answer / pb

argc is nothing but Argument Count
argv is nothing Argument Vector (or) Argument Value which
is array of Strings.

The first argument to the Command line is always the
Program Name.

argc contains no. of Arguments that it passed including the
Program Name.So Leave the 1st Argument,

int i;
for(i=1;i<=argc;i++)
cout<<argv[i];

Is This Answer Correct ?    0 Yes 0 No

How to access command-line arguments?..

Answer / padmaraj

By using -->
int main(int argc, char * argv[])

In this statement the variable argc holds the at least one
argument of type int , the name of the file it self first
argument and *argv[] is array of char which takes the name
of file.......
If any correction plz E-mail me ...
Bye

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Code Interview Questions

void main() { static int i; while(i<=10) (i>2)?i++:i--; printf(ā€œ%dā€, i); }

2 Answers  


There are 21 people in a room. They have to form groups of 3 people each. How many combinations are possible? Write a C program to print the same.

1 Answers   TCS,


write a c-program to find gcd using recursive functions

5 Answers   HTC, Infotech,


write a program to find out roots of quadratic equation "x=-b+-(b^2-4ac0^-1/2/2a"

2 Answers  


Implement a t9 mobile dictionary. (Give code with explanation )

1 Answers   Amazon, Peak6, Yahoo,






Is the following statement a declaration/definition. Find what does it mean? int (*x)[10];

1 Answers  


Write a routine to implement the polymarker function

0 Answers   TCS,


main() { if ((1||0) && (0||1)) { printf("OK I am done."); } else { printf("OK I am gone."); } } a. OK I am done b. OK I am gone c. compile error d. none of the above

5 Answers   HCL,


main() { show(); } void show() { printf("I'm the greatest"); }

2 Answers  


#include <stdio.h> #define a 10 main() { #define a 50 printf("%d",a); }

2 Answers  


respected sir, i did my MCA in 2013 when i am going to attend to an interview i was asked about my project how will i explain my project could please help me in this and my project title is "Social Networking Site For Social Responsibility"

1 Answers   Genpact, Ozdocs,


#include<stdio.h> main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s=malloc(sizeof(struct xx)); printf("%d",s->x); printf("%s",s->name); }

1 Answers   TCS,


Categories