Poblem with Structural array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • huzzaa
    New Member
    • Apr 2007
    • 9

    #1

    Poblem with Structural array

    Hey, I am trying to declare an array of 12 structs that will hold information from a file input.

    I have my struct

    Code:
     
    struct month
    {
        float totalRain, highTemp, lowTemp, averageTemp;
    };

    and this is my array

    Code:
    struct month fullYear[12];
    These are my struct variables.

    Code:
    month jan, feb, mar, april, may, june, jul, aug, sept, oct, nov, dec;

    each of the struct variables will be placed in the array respectively, but I am unsure how to read the information from the file putting them in their rightfull place.


    The values in the input file will be separated by blanks. A sample single line in the input file might be:
    20.1 78.2 40.1


    How would I go about placing 20.1 into jan.totalRain in my array?



    I hope I explained myself clearly, If not just let me know.

    Thank you all for your help in advance.
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    Access jan by using month[0], feb with month[1], ... dec with month[11]. For your operations, instead of typing jan.totalRain = /* your code here */;, type month[0].totalRain = /* your code here */;

    Comment

    Working...