Sams Teach Yourself C in 21 Days

(singke) #1
In Review 621

CH 21 43: if( argc < 2 )
44: {
45: display_usage(“WEEK3”);
46: exit(1);
47: }
48:
49: /* Open file. */
CH 16 50: if ((fp = fopen( argv[1], “a+”)) == NULL)
51: {
52: fprintf( stderr, “%s(%d)—Error opening file %s”,
53: argv[0],__LINE__, argv[1]);
54: exit(1);
55: }
56:
57: while( cont == YES )
58: {
59: switch( display_menu() )
60: {
CH 18 61: case ‘1’: get_data(fp, argv[0], argv[1]); /* Day 18*/
62: break;
63: case ‘2’: display_report(fp);
64: break;
65: case ‘3’: look_up(fp);
66: break;
67: case ‘4’: printf(“\n\nThank you for using this program!\n”);
68: cont = NO;
69: break;
70: default: printf(“\n\nInvalid choice, Please select 1 to 4!”);
71: break;
72: }
73: }
CH 16 74: fclose(fp); /* close file */
75: return(0);
76: }
77:
78: /* display_menu() */
79:
80: int display_menu(void)
81: {
82: char ch, buf[20];
83:
84: printf( “\n”);
85: printf( “\n MENU”);
86: printf( “\n ========\n”);
87: printf( “\n1. Enter names”);
88: printf( “\n2. Print report”);
89: printf( “\n3. Look up number”);
90: printf( “\n4. Quit”);
91: printf( “\n\nEnter Selection ==> “);
92: gets(buf);
93: ch = *buf;

LISTINGR3.1 continued

34 448201x-W3R 8/13/02 11:22 AM Page 621

Free download pdf