i tried to read integer values from a file but it didnt work.
fscanf could only read strings.. why?
or am i not doing sumfin ryt??

here's my code:

 int a=0;
 FILE *p;
 p = fopen("Customer_Records.txt", "r");
                   fscanf(p, " %[^\n]", profile[a].name);
                   printf("\n %s", profile[a].name);
                   fscanf(p, " %[^\n]", profile[a].phone);
                   printf("\n %s", profile[a].phone);
                   fscanf(p, " %[^\n]", profile[a].email);
                   printf("\n %s",  profile[a].email);
                   fscanf(p, " %d %d %d", &profile[a].entry.day, &profile[a].entry.month, &profile[a].entry.year);
                   printf("\n %d/%d/%d", profile[a].entry.day, profile[a].entry.month, profile[a].entry.year);
                   fscanf(p, " %d", &profile[a].acct_no);
                   printf("\n %d %d", profile[a].acct_no);


i'm trying to locate a particular customer's record with this function and it seems to print the first record no matter what account no i enter. and it can't read the correct account number on the screen. it only shows 0's for all the int values. and sometimes shows the date when i dont ask for it like i hav now in the console.

this is the output:

 Account Name: Samira Ali
 Phone Number: 4214920
 E-mail Address: frtgfcvbnj

those values were jus trial values i entered and this is what's in the file(they'r all trial values):

Account Name: Samira Ali
Phone Number: 4214920
E-mail Address: frtgfcvbnj
Date of Application: 12/12/1212

Account Name: Sam li
Phone Number: 4215048
E-mail Address: werghgvf
Date of Application: 23/12/1999

Edited 3 Years Ago by mike_2000_17: Fixed formatting

If you take the time to read the rules on how to post and present your question, you might get better results.

Start with this and then go here
For convenience to the desperate and impatient those are shortcuts.

This article has been dead for over six months. Start a new discussion instead.