Hi, I got this problem when I was running my code. I am a beginner in this field so it'd be great to know what is the problem in my code. The error is when I finished putting in my input, it could not read my input and my filename.txt stopped working.
Code:
#include <stdio.h>#include <stdlib.h>
typedef struct details
{
char plateNo[50];
char vehicleType[50];
char carBrand[50];
int date;
int driverID;
char ticketNo[50];
}details;
int main ()
{
details b;
FILE *fpwrite,* fpread;
fpwrite - fopen ("data_test.txt", "w");
if( fpwrite == NULL )
{
printf("Error! File not found");
exit(1);
}
newEntry :
printf("\n---New Details---");
printf("\nPlate No. : ");
gets(b.plateNo);
printf("\nVehicle Type : ");
scanf("%s", &b.vehicleType);
printf("\nCar Brand : ");
scanf("%s", &b.carBrand);
printf("\nDate : (example: DD/MM/YY) \n");
scanf("%d", &b.date);
printf("\nDriver ID : ");
scanf("%d", &b.driverID);
printf("\nTicket Issued : ");
scanf("%d", &b.ticketNo);
fflush (stdin);
fwrite(&b,sizeof(b),10,fpwrite);
fclose(fpwrite);
fpread = fopen("data_test.txt", "r");
while (fread(&b, sizeof(b),10,fpread) > 0)
printf("%s\n %s\n %d\n %d\n %d\n",b.plateNo,b.vehicleType,b.carBrand,b.date,b.driverID,b.ticketNo);
fclose(fpread);
}