#include <stdio.h>
#include <conio.h>
typedef struct
{
char fname[12], lname[12];
}name;
FILE*info;
void main ()
{
int i;
name customer;
if((info=fopen("Customers.dat", "wb"))==NULL) //OPen file for writing
fprintf(stderr, "Error! Unable to store info");
else{
for(i=0;i<2; i++){//Accept 2 records
printf("Please enter name: ");
scanf("%s %s", customer.fname, customer.lname);
fwrite(&customer, sizeof(name), 1, info);
}//end for loop
} //end if
fclose(info); //close file after writing
if((info=fopen("Customers.dat", "rb"))==NULL) //Open file for reading
fprintf(stderr, "Error! Unable to open file");
else{
while(!feof(info)){ //Print info read from file
fread(&customer, sizeof(name), 1, info);
printf("\nThe name enter is %s %s", customer.fname, customer.lname);
}//end while .
}//end if
fclose(info);
getch();
}
I dont know if i'm not using "feof" correctly

New Topic/Question
Reply



MultiQuote







|