Command line arguments are passed to main in argc and argv.
#include <stdio.h>
int main( int argc, const char **argv ) {
const char * const is = (argc == 1) ? "is" : "are";
const char * const it = (argc == 1) ? "it" : "they";
const char * const s = (argc == 1) ? "" : "s";
const char **p = argv;
printf( "There %s %d argument%s\n", is, argc, s );
printf( "And here %s %s\n", it, is );
while ( *p ) {
printf( "%s\n", *p );
p++;
}
return 0;
}
There is 1 argument And here it is code/argv
There are 4 arguments And here they are code/argv foo bar batTOC | Prev | Next