The data file has weather data for Miami and Toronto (city name, the date, temperature, precipitation). I need to create a function that prints a struct but the values are in a .txt file. This is the file: (info.txt)
Miami,2,-6.4,0
Toronto,2,9.5,0.8
Miami,3,-11.7,0
Toronto,3,6.1,0
This is the struct:
struct Weather{
char location; //will be "M" or "T"
int daynum;
double temp;
double precip;
};
This is a parser function:
void parseLine(char toParse[], struct Weather * toLoad)
{
char * theToken;
theToken = strtok(toParse, ",");
toLoad->location = theToken[0];
theToken = strtok(NULL, ",");
toLoad->daynum = atoi(theToken);
theToken = strtok(NULL, ",");
if(theToken != NULL)
{
toLoad->temp = atof(theToken);
}
else
{
toLoad->temp = -400;
}
theToken = strtok(NULL, ",");
if(theToken != NULL)
{
toLoad->precip = atof(theToken);
}
else
{
toLoad->precip = -1.0;
}
}
So my question is how do I use the struct and the parse function to create another function that prints the values of location, daynum, temp, and precip.
Note: im using argc and argv in my main function. You should also know im new to file manipulation and so I'm not exactly sure how to use file functions correctly.
Edit: My primary problem is figuring out what to do in 'main' so that I can create the print function