How to access command-line arguments?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
main() { int i = 0xff ; printf("\n%d", i<<2); } a. 4 b. 512 c. 1020 d. 1024
How do you verify if the two sentences/phrases input is an anagram using predefined functions in string.h and by using arrays?
int i,j; for(i=0;i<=10;i++) { j+=5; assert(i<5); }
#define f(g,g2) g##g2 main() { int var12=100; printf("%d",f(var,12)); }
Under linux environment can u please provide a c code for computing sum of series 1-2+3-4+5......n terms and -1+2-3+4-5...n terms..
What are the following notations of defining functions known as? i. int abc(int a,float b) { /* some code */ } ii. int abc(a,b) int a; float b; { /* some code*/ }
main() { static int var = 5; printf("%d ",var--); if(var) main(); }
Give a oneline C expression to test whether a number is a power of 2?
25 Answers EA Electronic Arts, Google, Motorola,
main() { int i=5,j=6,z; printf("%d",i+++j); }
1. const char *a; 2. char* const a; 3. char const *a; -Differentiate the above declarations.
# include<stdio.h> aaa() { printf("hi"); } bbb(){ printf("hello"); } ccc(){ printf("bye"); } main() { int (*ptr[3])(); ptr[0]=aaa; ptr[1]=bbb; ptr[2]=ccc; ptr[2](); }
main() { signed int bit=512, mBit; { mBit = ~bit; bit = bit & ~bit ; printf("%d %d", bit, mBit); } } a. 0, 0 b. 0, 513 c. 512, 0 d. 0, -513
3 Answers HCL, Logical Computers,