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() { char *p = “ayqm”; char c; c = ++*p++; printf(“%c”,c); }
Write a function to find the depth of a binary tree.
13 Answers Adobe, Amazon, EFI, Imagination Technologies,
String copy logic in one line.
how to check whether a linked list is circular.
#include<stdio.h> main() { FILE *ptr; char i; ptr=fopen("zzz.c","r"); while((i=fgetch(ptr))!=EOF) printf("%c",i); }
What is data _null_? ,Explain with code when u need to use it in data step programming ?
Who could write how to find a prime number in dynamic array?
char inputString[100] = {0}; To get string input from the keyboard which one of the following is better? 1) gets(inputString) 2) fgets(inputString, sizeof(inputString), fp)
how can u draw a rectangle in C
53 Answers Accenture, CO, Codeblocks, Cognizant, HCL, Oracle, Punjab National Bank, SAP Labs, TCS, University, Wipro,
What are segment and offset addresses?
main() { char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcat(a,b)); } a. Hello b. Hello World c. HelloWorld d. None of the above
Predict the Output: int main() { int *p=(int *)2000; scanf("%d",2000); printf("%d",*p); return 0; } if input is 20 ,what will be print