author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Thu, 16 Apr 2009 12:49:13 +0200 | |
changeset 60 | 47c13ca8c4d0 |
parent 27 | 81a574d60c15 |
child 77 | 49e0babccb23 |
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]; |
|
27
81a574d60c15
typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
20 |
|
0 | 21 |
int counter = 0; |
27
81a574d60c15
typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
22 |
|
0 | 23 |
FILE *f; |
27
81a574d60c15
typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
24 |
|
0 | 25 |
int c, pure = 0; |
26 |
||
27 |
while ((c = getopt (argc, argv, "hp")) != -1) { |
|
28 |
printf ("Zeichen: %c\n", c); |
|
29 |
switch (c) { |
|
30 |
case 'h': |
|
31 |
usage (argv[0]); |
|
32 |
break; |
|
33 |
case 'p': |
|
34 |
pure = 1; |
|
35 |
break; |
|
36 |
default: |
|
37 |
printf ("Unknown Parameter: %s\n", argv[optind]); |
|
38 |
} |
|
39 |
printf ("GETOPT: %d : %s\n", optind, argv[optind]); |
|
40 |
} |
|
41 |
||
42 |
if (optind == argc) |
|
43 |
f = stdin; |
|
44 |
else |
|
45 |
f = fopen (argv[optind], "r"); |
|
46 |
||
47 |
if (!f) { |
|
48 |
perror ("Error opening file"); |
|
49 |
return EXIT_FAILURE; |
|
50 |
} |
|
51 |
||
52 |
*buffer = 0; |
|
53 |
||
54 |
while (fgets (buffer, 80, f) != NULL) { |
|
55 |
if (!pure) |
|
56 |
printf ("%4.4d: %s", counter++, buffer); |
|
57 |
else |
|
58 |
printf ("%s", buffer); |
|
59 |
*buffer = 0; |
|
60 |
} |
|
61 |
||
62 |
fclose (f); |
|
8
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
63 |
|
0 | 64 |
return EXIT_SUCCESS; |
65 |
} |