Thread: Looking for help with the array of structures problem :)

  1. #1
    Registered User
    Join Date
    Jun 2020

    Looking for help with the array of structures problem :)

    I'm trying to input the array of structs into the print_yearly_data function and then loop through the inputted array of structs, printing each individual structures data with the print_climate_data function.

    Is there a way to do this using the current methods or do i need to learn something new.

    Any help appreciated!

    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    void print_climate_data(struct climatedata a);
    void print_yearly_data(struct climatedata b[]);
    struct climatedata
      char month[10];
      float high;
      float mean;
      float low;
    int main(void)
      int m;
      struct climatedata auck[13];
      strcpy(auck[1].month, "Jan");
      strcpy(auck[2].month, "Feb");
      strcpy(auck[3].month, "Mar");
      strcpy(auck[4].month, "Apr");
      strcpy(auck[5].month, "May");
      strcpy(auck[6].month, "Jun");
      strcpy(auck[7].month, "Jul");
      strcpy(auck[8].month, "Aug");
      strcpy(auck[9].month, "Sep");
      strcpy(auck[10].month, "Oct");
      strcpy(auck[11].month, "Nov");
      strcpy(auck[12].month, "Dec");
      auck[1].high = 30.0f;
      auck[2].high = 30.5f;
      auck[3].high = 29.8f;
      auck[4].high = 26.0f;
      auck[5].high = 24.6f;
      auck[6].high = 23.8f;
      auck[7].high = 19.0f;
      auck[8].high = 20.6f;
      auck[9].high = 22.0f;
      auck[10].high = 23.6f;
      auck[11].high = 25.9f;
      auck[12].high = 28.3f;
      auck[1].low = 5.6f;
      auck[2].low = 8.7f;
      auck[3].low = 6.6f;
      auck[4].low = 3.9f;
      auck[5].low = 0.9f;
      auck[6].low = -1.1f;
      auck[7].low = -3.9f;
      auck[8].low = -1.7f;
      auck[9].low = 1.7f;
      auck[10].low = -0.6f;
      auck[11].low = 4.4f;
      auck[12].low = 7.0f;
      auck[1].mean = 19.1f;
      auck[2].mean = 19.7f;
      auck[3].mean = 18.4f;
      auck[4].mean = 16.1f;
      auck[5].mean = 14.0f;
      auck[6].mean = 11.8f;
      auck[7].mean = 10.9f;
      auck[8].mean = 11.3f;
      auck[9].mean = 12.7f;
      auck[10].mean = 14.2f;
      auck[11].mean = 15.7f;
      auck[12].mean = 17.8f;
      printf("Enter month number: ");
      scanf("%d", &m);
      return 0;
    void print_climate_data(struct climatedata a)
      printf("%s\n", a.month);
      printf("Record High: %.1f C\n", a.high);
      printf("Daily Mean: %.1f C\n", a.mean);
      printf("Record Low: %.1f C\n\n", a.low);
    void print_yearly_data(struct climatedata b[])
      for (int i = 1; i > 13; i++)
    Last edited by p1zzat1me; 06-09-2020 at 10:55 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > for (int i = 1; i > 13; i++)
    Try < instead.

    Other than that, it would seem to be fine.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2020
    Thanks a bunch
    Looking for help with the array of structures problem :)-tenor-gif

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array of structures problem !
    By raadys in forum C Programming
    Replies: 4
    Last Post: 09-13-2013, 07:53 AM
  2. Problem with array of pointers to structures and such
    By bungkai in forum C Programming
    Replies: 6
    Last Post: 07-09-2011, 04:31 PM
  3. Problem with array of structures
    By Sonia in forum C Programming
    Replies: 10
    Last Post: 10-12-2010, 03:37 AM
  4. Problem filling an array of structures
    By bluetxxth in forum C Programming
    Replies: 7
    Last Post: 03-11-2010, 02:29 AM
  5. Replies: 6
    Last Post: 02-15-2005, 11:20 PM

Tags for this Thread