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() { while (strcmp(“some”,”some\0”)) printf(“Strings are not equal\n”); }

1 Answers  


#define a 10 int main() { printf("%d..",a); foo(); printf("%d..",a); return 0; } void foo() { #undef a #define a 50 }

3 Answers  


how to concatenate the two strings

1 Answers  


You are given any character string. Find the number of sets of vowels that come in the order of aeiou in the given string. For eg., let the given string be DIPLOMATIC. The answer returned must be "The number of sets is 2" and "The sets are "IO and AI". Vowels that form a singleton set must be neglected. Try to post the program executable in gcc or g++ or in java.

3 Answers  


1 o 1 1 0 1 0 1 0 1 1 0 1 0 1 how to design this function format in c-language ?

2 Answers  






void func1(int (*a)[10]) { printf("Ok it works"); } void func2(int a[][10]) { printf("Will this work?"); } main() { int a[10][10]; func1(a); func2(a); } a. Ok it works b. Will this work? c. Ok it worksWill this work? d. None of the above

1 Answers   HCL,


#define int char main() { int i=65; printf("sizeof(i)=%d",sizeof(i)); }

1 Answers  


how to programme using switch statements and fuctions, a programme that will output two even numbers, two odd numbers and two prime numbers of the users chioce.

0 Answers   Mbarara University of Science and Technology,


write a c-program to find gcd using recursive functions

5 Answers   HTC, Infotech,


main( ) { char *q; int j; for (j=0; j<3; j++) scanf(“%s” ,(q+j)); for (j=0; j<3; j++) printf(“%c” ,*(q+j)); for (j=0; j<3; j++) printf(“%s” ,(q+j)); }

1 Answers  


write a simple calculator c program to perform addition, subtraction, mul and div.

0 Answers   United Healthcare, Virtusa,


Write a prog to accept a given string in any order and flash error if any of the character is different. For example : If abc is the input then abc, bca, cba, cab bac are acceptable, but aac or bcd are unacceptable.

5 Answers   Amazon, Microsoft,


Categories