summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2013-10-02 16:07:27 +0100
committerTom Hacohen <tom@stosb.com>2013-10-02 16:07:27 +0100
commit9f56f6a31762df8ae7f26e2481ea0032e1e90450 (patch)
treeb008fe41e9ef5059d136bcdf0b22b72410bcbc20
parent9c620dc8401af7912a08a63bc48189980c315029 (diff)
parent3a7e216becca71a920a124bea63d91390ca60bdc (diff)
(Merge) implement generic argument printing.
This let's users just choose the argument they'd like to print. Merge branch 'generic-argument-printing'
-rw-r--r--main.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/main.c b/main.c
index 6101175..ca54bc4 100644
--- a/main.c
+++ b/main.c
@@ -1,11 +1,18 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <stdlib.h>
2 3
3int 4int
4main(int argc, char *argv[]) 5main(int argc, char *argv[])
5{ 6{
6 printf("arg 1: %s\n", argv[0]); 7 unsigned int argument = 0;
8
7 if (argc >= 2) 9 if (argc >= 2)
8 printf("arg 2: %s\n", argv[1]); 10 argument = atoi(argv[1]) - 1;
11
12 if (argument < (unsigned) argc)
13 printf("arg %d: %s\n", argument, argv[argument]);
14 else
15 return 1;
9 16
10 return 0; 17 return 0;
11} 18}