Read Command-Line Arguments: Difference between revisions

Content added Content deleted
(→‎{{header|C++}}: fixed argv declaration, rm ';' in #include)
(C version)
Line 1: Line 1:
{{task}}Read the command line arguments, display the total number, and display each one, including any reference to the program itself. (i.e., if the language includes the name and path of the executable as one of the arguments, include it.)
{{task}}Read the command line arguments, display the total number, and display each one, including any reference to the program itself. (i.e., if the language includes the name and path of the executable as one of the arguments, include it.)

=={{header|C}}==

<pre>
#include<stdio.h>

int main(int argc, char *argv[])
{
int narg;

printf("There are %d arguments\n", argc);
for(narg=0; narg<argc; ++narg)
printf("Argument #%d is %s.\n", narg, argv[narg]);

return 0;
}
</pre>


=={{header|C++}}==
=={{header|C++}}==