/*
Fig. 11.15: fig11_15.c
Reading a random access file sequentially
*/
#include <stdio.h>
/* structure declaration */
struct clientData {
int acctNum;
char lastName[ 15 ];
char firstName[ 10 ];
double balance;
};
int main(void) {
FILE *cfPtr;
struct clientData client = { 0, "", "", 0.0 };
if ( ( cfPtr = fopen( "credit.dat", "r" ) ) == NULL ) {
printf( "File could not be opened.\n" );
}
else {
printf( "%-6s%-16s%-11s%10s\n",
"Acct",
"Last Name",
"First Name",
"Balance" );
while (!feof(cfPtr)) {
fread(&client, sizeof(struct clientData), 1, cfPtr);
if ( client.acctNum != 0 ) {
printf( "%-6d%-16s%-11s%10.2f\n",
client.acctNum,
client.lastName,
client.firstName,
client.balance );
} /* end if */
} /* end while */
fclose( cfPtr );
} /* end else */
return 0;
}
/**************************************************************************
* (C) Copyright 2000 by Deitel & Associates, Inc. and Prentice Hall. *
* All Rights Reserved. *
* *
* DISCLAIMER: The authors and publisher of this book have used their *
* best efforts in preparing the book. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or *
* consequential damages in connection with, or arising out of, the *
* furnishing, performance, or use of these programs. *
*************************************************************************/