Problem File:
[well lol], [wtf bro? 24], [0183188383], [3000.000000], [4000.000000], [12/12/2012]
[chow hai], [pukima jalan], [6969696969], [6969.000000], [6969699.000000], [6/9/1969]
Code:
typedef struct Customer {
char name[50];
char billing_address[100];
char phone_number[15];
double amount_paid;
double amount_due;
char date[20];
} Customer;
Customer customer;
FILE *file = fopen("customers.txt", "ab+");
while (!feof(file)) {
fscanf(file, "[%s], [%s], [%s], [%lf], [%lf], [%s]\n", &customer.name, &customer.billing_address, customer.phone_number, &customer.amount_paid, &customer.amount_due, customer.date);
}
Problem:
In the above code, what I'm trying to do is parse each record value into the appropriate field in the Customer
structure. Now we do know that "%s" will not read spaces. How would I read a value like "well lol" in the record since %s
will not work.
Why is it not a duplicate?
I need to parse the entire line, and not just accept one value after the other as the supposedly duplicate answer.
Update on why it's not a duplicate:
while (!feof(file)) {
fscanf(file, "[%[^\\n]], [%[^\\n]], [%[^\\n]], [%lf], [%lf], [%[^\\n]]\n", customer.name, customer.billing_address, customer.phone_number, &customer.amount_paid, &customer.amount_due, customer.date);
printf("%s", customer.billing_address);
if (strcmp(customer.name, search) == 0) {
printf("FOUND!!!");
}
}
I've updated the code as told, but my output is still wrong. I believe there's something else wrong. Output:
SEARCH A CUSTOMER PROFILE
=========================
Customer Name: a
���