How to print a struct using a file in C
<p>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)</p>

<pre><code>Miami,2,-6.4,0
Toronto,2,9.5,0.8
Miami,3,-11.7,0
Toronto,3,6.1,0
</code></pre>

<p>This is the struct:</p>

<pre><code>struct Weather{

    char location;  //will be "M" or "T"
    int daynum;
    double temp;
    double precip;
};
</code></pre>

<p>This is a parser function:</p>

<pre><code>void parseLine(char toParse[], struct Weather * toLoad)
{     
    char * theToken;     
    theToken = strtok(toParse, ",");     
    toLoad-&gt;location = theToken[0];     
    theToken = strtok(NULL, ",");     
    toLoad-&gt;daynum = atoi(theToken);     
    theToken = strtok(NULL, ",");     
    if(theToken != NULL)
    {         
        toLoad-&gt;temp = atof(theToken);     
    }     
    else     
    {         
        toLoad-&gt;temp = -400;     
    }     
    theToken = strtok(NULL, ",");     
    if(theToken != NULL)     
    {         
        toLoad-&gt;precip = atof(theToken);     
    }     
    else     
    {         
        toLoad-&gt;precip = -1.0; 
    }
}
</code></pre>

<p>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.</p>

<p>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.</p>

<p>Edit: My primary problem is figuring out what to do in 'main' so that I can create the print function</p>