Code:
#include <stdio.h>
int main (void ){
struct clientdata{
int acct;
char name[20];
char lastn[20];
int age;
char sex[2];
float height;
float weight;
int membership;
};//end struct
int i;
int j=101;
struct clientdata client={0, "", "", 0, "", 0.0, 0.0, 0};
FILE *cfptr;
if((cfprt=fopen( "customers.dat", "wb+" ))== NULL) {
printf( "file could not be opened\n");}
else{
for(i=101; i <= 109;i++){
fwrite(&client, sizeof( struct clientdata), 1, cfptr);
}
printf("Enter acct number"
"(101 to 105, 0 to end input\n");
scanf("%d", &client.acct);
while(client.acct != 0){
printf("Enter name, last name, age, sex\n");
printf("height, weight, and membership years\n");
fscanf( stdin, "%s%S%d%s%f%f%d", client.name, client.lastn,
&client.age, client.sex, &client.height, &client.weight, &client.membership);
fseek( cfptr, (client.acct - 1) *
sizeof( struct clientdata), SEEK_SET);
fwrite(&client, sizeof( struct clientdata), 1, cfptr);
printf("Enter acct number\n");
scanf("%d", &client.acct);
} // end while
printf("%-5s%-20S%-20s%-4s%-5s%-5s%-5s%-11s\n", "Acct", "Name",
"last name", "Age", "sex", "height", "weight", "membership");
while(j<=109){
fread(&client, sizeof(struct clientdata), 1, cfptr);
if(client.acct !=0){
printf("%-5d%-20S%-20s%-4d%-5s%-5f%-5f%-11d\n",
client.acct, client.name, client.lastn,
client.age, client.sex, client.height, client.weight, client.membership);
} //end if
} //end 2nd.while
fclose(cfptr);
} //end else
return 0;
} //ends main