Programming language: C Write program words that prints out the words from the c
ID: 3887405 • Letter: P
Question
Programming language: C
Write program words that prints out the words from the command line on different lines. Note
what “from the command line” means. This program will not have any input commands (like
scanf) in it. The first line of your main program will be something like
• int main( int argc, char ** argv )
When you run your program, the first parameter argc will contain the number of words on the
line that runs the program. Thus, in the example below, argc will contain 11. Notice that argv
(argument vector) is a two dimensional array of characters. In the example below, argv[0] will
have “./words” and agrv[1] will have the string “To”. And, of course, argv[1][0] will have the
character ‘T’.
> make words
...
> ./words To be or not to be? That is the question.
To
be
or
not
to
be?
That
is
the
question.
Explanation / Answer
#include <stdio.h>
int main(int argc,char **argv)
{
int i;
for(i=1;i<argc;i++)
{
printf("%s ",argv[i]);
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.