fscanf problem.. PLS HELP
The value of my e.pdes is wrong.. It should be this "ASUS 101 Motherboard" not this "ASUS 101 Motherboard 4500.00". And e.price to becomes "0.00"
Please help, thanks?
Code:
#include<stdio.h>
#include<conio.h>
struct forInfo
{
char pnum[50];
char pdes[50];
float price;
} e;
void view()
{
FILE *fp = fopen("master.dat","r");
while((fscanf(fp, "%s\t%[^\n]s\t%f\n", &e.pnum, &e.pdes, &e.price)) != EOF)
{
printf("%s\t%s\t%0.2f\n", e.pnum, e.pdes, e.price);
}
fclose(fp);
}
int main()
{
view();
getch();
return 0;
}
MASTER.DAT
Code:
ASUS101112 ASUS 101 Motherboard 4500.00
BOKA118001 BOKA 118 Speakers 3500.00
ASUS101112 ASUS 110 Motherboard 4500.00
BOKA118001 BOKA 118 Speakers 3500.00
OUTPUT
Code:
ASUS101112 ASUS 101 Motherboard 4500.00 0.00
BOKA118001 BOKA 118 Speakers 3500.00 0.00
ASUS101112 ASUS 110 Motherboard 4500.00 0.00
BOKA118001 BOKA 118 Speakers 3500.00 0.00