kleiner auffschrischungskurs compilerbau...
committer: Markus Bröker <mbroeker@largo.homelinux.org>
/**
* test/demos/numerierung.c
* Copyright (C) 2008 Markus Broeker
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <getopt.h>
void usage (char *cmd)
{
printf ("Usage: %s [-h] [-t] [-v] [file]\n", cmd);
exit (0);
}
int main (int argc, char **argv)
{
char buffer[81];
int counter = 0;
FILE *f;
int c, pure = 0;
while ((c = getopt (argc, argv, "hp")) != -1) {
printf ("Zeichen: %c\n", c);
switch (c) {
case 'h':
usage (argv[0]);
break;
case 'p':
pure = 1;
break;
default:
printf ("Unknown Parameter: %s\n", argv[optind]);
}
printf ("GETOPT: %d : %s\n", optind, argv[optind]);
}
if (optind == argc)
f = stdin;
else
f = fopen (argv[optind], "r");
if (!f) {
perror ("Error opening file");
return EXIT_FAILURE;
}
*buffer = 0;
while (fgets (buffer, 80, f) != NULL) {
if (!pure)
printf ("%4.4d: %s", counter++, buffer);
else
printf ("%s", buffer);
*buffer = 0;
}
fclose (f);
return EXIT_SUCCESS;
}