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

main() { char string[]="Hello World"; display(string); } void display(char *string) { printf("%s",string); }

2 Answers   Wipro,


Write a program to receive an integer and find its octal equivalent?

7 Answers  


Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2) without making use of any floating point computations at all.

2 Answers   Mentor Graphics, Microsoft,


plz send me all data structure related programs

2 Answers  


int i; main(){ int t; for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) printf("%d--",t--); } // If the inputs are 0,1,2,3 find the o/p

2 Answers  






main() { int i=4,j=7; j = j || i++ && printf("YOU CAN"); printf("%d %d", i, j); }

1 Answers  


Write a C function to search a number in the given list of numbers. donot use printf and scanf

5 Answers   Honeywell, TCS,


plz send me all data structure related programs

2 Answers  


void main() { char a[]="12345\0"; int i=strlen(a); printf("here in 3 %d\n",++i); }

3 Answers  


can you use proc sql to manpulate a data set or would u prefer to use proc report ? if so why ? make up an example and explain in detail

0 Answers   TCS,


#define prod(a,b) a*b main() { int x=3,y=4; printf("%d",prod(x+2,y-1)); }

1 Answers  


main() { unsigned char i=0; for(;i>=0;i++) ; printf("%d\n",i); }

1 Answers  


Categories