This is a variant on the traditional "Hello World" programme:
/* The standard IO libs are required : */
#include <stdio.h>
/* Begin main prog --- get command-line args : */
main (int argc, char *argv[]) {
printf("Hello ");
/* If there are some command-line args, print each out in turn : */
if (argc > 1) {
int i;
for(i=1; i < argc; i++) printf("%s ",argv[i]);
}
printf(" - welcome \n");
}
|
Compile source to binary named c1, then run:
$ c1
Hello - welcome
$
|
$ c1 Iain Stinson
Hello Iain Stinson - welcome
$
|
| The Above Programme Step-by-Step |
i = 1;
while (i < argc) {
printf("%s ",argv[i]);
i++;
}
|
| ...previous | up (conts) | next... |