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 |
How we print the table of 2 using for loop in c programing?
print a semicolon using Cprogram without using a semicolon any where in the C code in ur program!!
35 Answers Tata Elxsi, TCS, VI eTrans,
Is the following code legal? void main() { typedef struct a aType; aType someVariable; struct a { int x; aType *b; }; }
How can i find first 5 natural Numbers without using any loop in c language????????
void pascal f(int i,int j,int k) { printf(“%d %d %d”,i, j, k); } void cdecl f(int i,int j,int k) { printf(“%d %d %d”,i, j, k); } main() { int i=10; f(i++,i++,i++); printf(" %d\n",i); i=10; f(i++,i++,i++); printf(" %d",i); }
{ int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",(*ptr)+++*ptr++); }
plz send me all data structure related programs
Write a C program that defines a 2-dimentional integer array called A [50][50]. Then the elements of this array should randomly be initialized either to 1 or 0. The program should then print out all the elements in the diagonal (i.e. a[0][0], a[1][1],a[2][2], a[3][3], ……..a[49][49]). Finally, print out how many zeros and ones in the diagonal.
main() { int x=5; clrscr(); for(;x<= 0;x--) { printf("x=%d ", x--); } } a. 5, 3, 1 b. 5, 2, 1, c. 5, 3, 1, -1, 3 d. –3, -1, 1, 3, 5
What is the output of the program given below main() { signed char i=0; for(;i>=0;i++) ; printf("%d\n",i); }
main() { main(); }
Code for 1>"ascii to string" 2>"string to ascii"
1 Answers Aricent, Global Logic,