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(){ unsigned int i; for(i=1;i>-2;i--) printf("c aptitude"); }

2 Answers  


main() { int i; printf("%d",scanf("%d",&i)); // value 10 is given as input here }

2 Answers   IBM,


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); }

1 Answers  


#include<stdio.h> main() { FILE *ptr; char i; ptr=fopen("zzz.c","r"); while((i=fgetch(ptr))!=EOF) printf("%c",i); }

1 Answers  


Derive expression for converting RGB color parameters to HSV values

1 Answers  






How can u say that a given point is in a triangle? 1. with the co-ordinates of the 3 vertices specified. 2. with only the co-ordinates of the top vertex given.

1 Answers  


How do you create a really large matrix (i.e. 3500x3500) in C without having the program crash? I can only reach up to 2500. It must have something to do with lack of memory. Please help!

1 Answers  


struct Foo { char *pName; char *pAddress; }; main() { struct Foo *obj = malloc(sizeof(struct Foo)); clrscr(); obj->pName = malloc(100); obj->pAddress = malloc(100); strcpy(obj->pName,"Your Name"); strcpy(obj->pAddress, "Your Address"); free(obj); printf("%s", obj->pName); printf("%s", obj->pAddress); } a. Your Name, Your Address b. Your Address, Your Address c. Your Name Your Name d. None of the above

2 Answers   HCL,


void main() { if(~0 == (unsigned int)-1) printf(“You can answer this if you know how values are represented in memory”); }

1 Answers  


1. const char *a; 2. char* const a; 3. char const *a; -Differentiate the above declarations.

3 Answers  


main() { char a[4]="HELLO"; printf("%s",a); }

3 Answers   CSC,


what is brs test reply me email me kashifabbas514@gmail.com

0 Answers  


Categories