#include <stdio.h>
// clientData structure definition
struct clientData {
unsigned int acctNum; // account number
char lastName[15]; // account last name
char firstName[10]; // account first name
double balance; // account balance
}; // end structure clientData
int main()
{
FILE *cptr;
int result;
if((cptr = fopen("credit.dat","rb")) == NULL)
{
puts("File could not opened");
}
else
{
struct clientData client={0,"","",0.0};
printf("%-6s%-16s%-11s%10s \n","Acct","Last name","First Name","Balance");
//fread(&client,sizeof(struct clientData),1,cptr);
while(!feof(cptr))
{
fread(&client,sizeof(struct clientData),1,cptr);
if ( client.acctNum != 0)
{
printf("%-6d%-16s%-11s%10f\n",client.acctNum,client.lastName,client.firstName,client.balance);
}
}
fclose(cptr);
}
} // end main
Output
Views: 0