Sams Teach Yourself C in 21 Days

(singke) #1
In Review 623

145: if(fseek( fp, 0, SEEK_SET ) == 0)
146: {
147: fread(&rec, 1, sizeof(rec), fp);
148: while(!feof(fp))
149: {
150: fprintf(stdout,”\n\t%s, %s %c %s”, rec.lname,
151: rec.fname, rec.mname[0],
152: rec.phone);
153: num_of_recs++;
154: fread(&rec, 1, sizeof(rec), fp);
155: }
156: fprintf(stdout, “\n\nTotal number of records: %d”,
157: num_of_recs);
158: fprintf(stdout, “\n\n* * * End of Report * * *”);
159: }
160: else
161: fprintf( stderr, “\n\n*** ERROR WITH REPORT ***\n”);
162: }
163:
164: /**************************************************
165: * Function: continue_function()
166: **************************************************/
167:
168: int continue_function( void )
169: {
170: char ch, buf[20];
171: do
172: {
173: printf(“\n\nDo you wish to enter another? (Y)es/(N)o “);
174: gets(buf);
175: ch = *buf;
176: } while( strchr( “NnYy”, ch) == NULL );
177:
178: if(ch == ‘n’ || ch == ‘N’)
179: return(NO);
180: else
181: return(YES);
182: }
183:
184: /**********************************************************
185: * Function: display_usage()
186: ***********************************************************/
187:
188: void display_usage( char *filename )
189: {
190: printf(“\n\nUSAGE: %s filename”, filename );
191: printf(“\n\n where filename is a file to store people\’s names”);
192: printf(“\n and phone numbers.\n\n”);
193: }
194:
195: /**********************************************

LISTINGR3.1 continued

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

Free download pdf