author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Sat, 13 Dec 2008 17:58:08 +0100 | |
changeset 16 | 2b4ef74a16aa |
parent 9 | c3fecc82ade6 |
child 27 | 81a574d60c15 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
9
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
8
diff
changeset
|
2 |
* test/demos/numerierung.c |
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
8
diff
changeset
|
3 |
* Copyright (C) 2008 Markus Broeker |
0 | 4 |
*/ |
5 |
||
6 |
#include <stdio.h> |
|
7 |
#include <stdlib.h> |
|
8 |
#include <errno.h> |
|
9 |
#include <getopt.h> |
|
10 |
||
11 |
void usage (char *cmd) |
|
12 |
{ |
|
13 |
printf ("Usage: %s [-h] [-t] [-v] [file]\n", cmd); |
|
14 |
exit (0); |
|
15 |
} |
|
16 |
||
17 |
int main (int argc, char **argv) |
|
18 |
{ |
|
19 |
char buffer[81]; |
|
20 |
int counter = 0; |
|
21 |
FILE *f; |
|
22 |
int c, pure = 0; |
|
23 |
||
24 |
while ((c = getopt (argc, argv, "hp")) != -1) { |
|
25 |
printf ("Zeichen: %c\n", c); |
|
26 |
switch (c) { |
|
27 |
case 'h': |
|
28 |
usage (argv[0]); |
|
29 |
break; |
|
30 |
case 'p': |
|
31 |
pure = 1; |
|
32 |
break; |
|
33 |
default: |
|
34 |
printf ("Unknown Parameter: %s\n", argv[optind]); |
|
35 |
} |
|
36 |
printf ("GETOPT: %d : %s\n", optind, argv[optind]); |
|
37 |
} |
|
38 |
||
39 |
if (optind == argc) |
|
40 |
f = stdin; |
|
41 |
else |
|
42 |
f = fopen (argv[optind], "r"); |
|
43 |
||
44 |
if (!f) { |
|
45 |
perror ("Error opening file"); |
|
46 |
return EXIT_FAILURE; |
|
47 |
} |
|
48 |
||
49 |
*buffer = 0; |
|
50 |
||
51 |
while (fgets (buffer, 80, f) != NULL) { |
|
52 |
if (!pure) |
|
53 |
printf ("%4.4d: %s", counter++, buffer); |
|
54 |
else |
|
55 |
printf ("%s", buffer); |
|
56 |
*buffer = 0; |
|
57 |
} |
|
58 |
||
59 |
fclose (f); |
|
8
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
60 |
|
0 | 61 |
return EXIT_SUCCESS; |
62 |
} |