Having problems reading info from a data file into an array of structures. The first time through, it gets the origin state and destin city correct, but all the other information is wrong. The origin City is storing the first three letters of the origin city, but also the origin state. (ie BalMD instead of Baltimore).
Also, I'm not sure waht the "200" means in fgets. I've toyed around with that ranging anywhere from 100 to 1000, but still get the same results.
Thanks.
Code:
typedef struct leg
{
char originCity[20];
char originState[3];
char destinCity[20];
char destinState[3];
int nights;
int miles;
}LEG;
struct leg *GetLegInfo (int numLegs, FILE *ifp, LEG *legs)
{
int i;
for (i = 0; i < numLegs; i++)
{
/* fill arrary of legs */
fgets (legs[i].originCity, 200, ifp);
fgets (legs[i].originState, 200, ifp);
fgets (legs[i].destinCity, 200, ifp);
fgets (legs[i].destinState, 200, ifp);
fscanf (ifp, "%d", &legs[i].nights);
fscanf (ifp, "%d", &legs[i].miles);
}
fclose (ifp);
return (legs);
}