File: 14_05.c

package info (click to toggle)
c-cpp-reference 2.0.2-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 8,012 kB
  • ctags: 4,612
  • sloc: ansic: 26,960; sh: 11,014; perl: 1,854; cpp: 1,324; asm: 1,239; python: 258; makefile: 115; java: 77; awk: 34; csh: 9
file content (63 lines) | stat: -rw-r--r-- 2,591 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/********************************************************
 * Database -- A very simple database program to        *
 *              lookup names in a hardcoded list.       *
 *                                                      *
 * Usage:                                               *
 *      database [-S<file>] [-P<file>]                  *
 *                                                      *
 *      -S<file>        Specify save file for           *
 *                      debugging purposes.             *
 *                                                      *
 *      -P<file>        Specify playback file for       *
 *                      debugging or demonstration.     *
 *                                                      *
 *                                                      *
 *              Program will ask you for a name.        *
 *              Enter the name; it will tell you if     *
 *              it is the list.                         *
 *                                                      *
 *              A blank name terminates the program.    *
 ********************************************************/
#include <stdio.h>

FILE *save_file = NULL; /* Save file if any */
FILE *playback_file = NULL;     /* Playback file if any */
char *extended_fgets(char *, int, FILE *);

main(int argc, char *argv[])
{
    char name[80];      /* a name to lookup */
    char *save_file_name; /* Name of the save file */
    char *playback_file_name; /* Name of the playback file */

    int lookup(char *); /* lookup a name */

    while ((argc > 1) && (argv[1][0] == '-')) {
        switch (argv[1][1]) {
            case 'S':
                save_file_name = &argv[1][2];
                save_file = fopen(save_file_name, "w");
                if (save_file == NULL) 
                    (void)fprintf(stderr,
                        "Warning:Unable to open save file %s\n",
                        save_file_name);
                break;
            case 'P':
                playback_file_name = &argv[1][2];
                playback_file = fopen(playback_file_name, "r");
                if (playback_file == NULL) {
                    (void)fprintf(stderr,
                        "Error:Unable to open playback file %s\n",
                        playback_file_name);
                    exit (8);
                }
                break;
            default:
                (void)fprintf(stderr,"Bad option: %s\n", argv[1]);
                exit (8);
        }
        argc--;
        argv++;
    }    

    /* ... rest of program ... */