Q:

C program to print all arguments given through command line

0

C program to print all arguments given through command line

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

#include <stdio.h>

int main(int argc, char *argv[])
{
	int counter;
	for(counter=0; counter<argc; counter++)
		printf("argv[%2d]: %s\n",counter,argv[counter]);
	
	return 0;
}

Output

sh-4.2$ ./main Hello world "how are you?" 
argv[ 0]: ./main
argv[ 1]: Hello 
argv[ 2]: world
argv[ 3]: how are you?

Consider the output

./mainHello, and world are the single word argument while "how are you?" is multiple words arguments, to pass multiple words in command line, we can enclose them in double quotes.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C program to find sum of two numbers using command... >>