Jump to content

Read Command-Line Arguments: Difference between revisions

C version
(→‎{{header|C++}}: fixed argv declaration, rm ';' in #include)
(C version)
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.)
 
=={{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++}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.