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 |
void main() { static int i; while(i<=10) (i>2)?i++:i--; printf(ā%dā, i); }
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.
write a c-program to find gcd using recursive functions
write a program to find out roots of quadratic equation "x=-b+-(b^2-4ac0^-1/2/2a"
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];
Write a routine to implement the polymarker function
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
main() { show(); } void show() { printf("I'm the greatest"); }
#include <stdio.h> #define a 10 main() { #define a 50 printf("%d",a); }
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"
#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); }