CODE :-
while ( fscanf ( fp,"%s %d %f", e.name, &e.age, &e.bs ) !=EOF )
{
printf ( "%s %d %f\n", e.name, e.age, e.bs ) ;
}
Say I am having following sentences in a file:-
fname lname 20 200000
fname1 lname1 30 50000
The desired output is :-
fname lname 20 200000.0000
fname1 lname1 30 50000.0000
But the output I am getting is :-
fname (garbage value) (garbage value)
lname 20 200000.0000
fname1 20 200000.0000
lname1 30 50000.0000
The above problem is due to the fact that %s
do not read white spaces, hence it is splitting my fname lname
into two parts.
Is there any solution to get the desired output?