Question: #include struct Invoice { char customerName [ 5 0 ] ; int customerId; char dateOfPurchase [ 1 0 ] ; float amountOfPurchase; int billNumber; }

#include
struct Invoice {
char customerName[50];
int customerId;
char dateOfPurchase[10];
float amountOfPurchase;
int billNumber;
};
int main(){
FILE *file = fopen("invoice.txt","rb"); // Open in binary read mode
struct Invoice bill;
int billNumberToSearch;
if (file == NULL){
perror("Error opening the file");
return 1;
}
printf("Enter bill number to search: ");
scanf("%d", &billNumberToSearch);
while(fread(&bill, sizeof(struct Invoice),1, file)){
if(bill.billNumber == billNumberToSearch){
printf("Customer Name: %s
", bill.customerName);
printf("Customer ID: %d
", bill.customerId);
printf("Date of Purchase: %s
", bill.dateOfPurchase);
printf("Amount of Purchase: %.2f
", bill.amountOfPurchase);
printf("Bill Number: %d
", bill.billNumber);
fclose(file);
return 0;
}
}
printf("No bill found with the given number.
");
fclose(file);
return 0;
}
what is the output for this

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!