Sams Teach Yourself C in 21 Days

(singke) #1
622 Week 3

94: return(ch);
95: }
96:
97: /****************************************************
98: Function: get_data()
99: *****************************************************/
100:
101: void get_data(FILE *fp, char *progname, char *filename)
102: {
103: int cont = YES;
104:
105: while( cont == YES )
106: {
107: printf(“\n\nPlease enter information: “ );
108:
109: printf(“\n\nEnter first name: “);
110: gets(rec.fname);
111: printf(“\nEnter middle name: “);
112: gets(rec.mname);
113: printf(“\nEnter last name: “);
114: gets(rec.lname);
115: printf(“\nEnter phone in 123-4567 format: “);
116: gets(rec.phone);
117:
CH 16 118: if (fseek( fp, 0, SEEK_END ) == 0)
119: if( fwrite(&rec, 1, sizeof(rec), fp) != sizeof(rec))
120: {
121: fprintf( stderr, “%s(%d) Error writing to file %s”,
122: progname,__LINE__, filename);
123: exit(2);
124: }
125: cont = continue_function();
126: }
127: }
128:
129: /********************************************************
130: Function: display_report()
131: Purpose: To print out the formatted names and numbers
132: of people in the file.
133: *********************************************************/
134:
135: void display_report(FILE *fp)
136: {
137: time_t rtime;
138: int num_of_recs = 0;
139:
140: time(&rtime);
141:
142: fprintf(stdout, “\n\nRun Time: %s”, ctime( &rtime));
143: fprintf(stdout, “\nPhone number report\n”);
144:

LISTINGR3.1 continued

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

Free download pdf