Hi,
I am supposed to read data from an input file with following information
16 //number of destinations//
Baltimore //origin city//
MD //origin state//
Lewes //destination state//
DE //destination state//
117.0 //miles b/w previous location and and this one//
160 //estimated driving time//
Ferry //place to visit in that location//
0 //no. of nights spent//
0.00 //cost of food//
0.00 //cost of admission and misc. fees//
Cape_May
NJ
22.2
79
Victorian_Houses
1
290.00
43.50
.....
and so on...
I told what the data represents using //..........//
and I have this structure declared
typedef struct city
{
char originCity[NAME_SIZE];
char originState[NAME_SIZE];
char destinCity[NAME_SIZE];
char destinState[NAME_SIZE];
float miles;
int hours;
int minutes;
char attraction[NAME_SIZE];
int nights;
float food;
float admission;
}CITY;
After opening the file I read in the first three lines of data with this code
fscanf(ifp, "%d", &destinNum);
fscanf(ifp, "%s", originCity);
fscanf(ifp, "%s", originState);
for the rest of the input file Im using this for loop
for (i = 0; i < MAXd; i++)
{
fscanf(ifp, "%s", city[i].destinCity);
fscanf(ifp, "%s", city[i].destinState);
fscanf(ifp, "%f", &city[i].miles);
fscanf(ifp, "%d", &city[i].hours);
fscanf(ifp, "%d", &city[i].minutes);
fscanf(ifp, "%s", city[i].attraction);
fscanf(ifp, "%d", &city[i].nights);
fscanf(ifp, "%f", &city[i].food);
fscanf(ifp, "%f", &lcity[i].admission);
}
I thought this would read the line 4 - 16 using for-loop for rest of locations in input file and then I would be able to print and manipulate from it. But when I print for example using this command
printf("%s", city[2].hours);
I only get garbage. Am I reading the file in wrong way? Or something else
would appreciate some help