Structs in C

Purpose

Download Files

Exercise

  1. weatherday.h contains the struct definition of WeatherDay. In weatherday.c, declare declare a static variable called day1 of type WeatherDay in function main().

  2. Now create a pointer of type WeatherDay (call it dayptr) and set it to point to variable day1 in function main()

  3. Complete the printWD() in weatherday.c to print data of the WeatherDay struct

  4. Complete function avgTemp in weatherday.c. Call it in main function to give you the average temperature for dayptr.

  5. Complete intialize(WeatherDay * day) in weatherday.c, such that all the data of day is intialized to zero
  6. Instead of intializing the data of day1, ask user to enter the values. Use dayptr to scan in the values using scanf().

  7. Create a dynamic array of WeatherDay of size 5.
    1. Access the third element of the array and intialize the data to value of your choice. Then call the printDW and avgTemp for the third element.
    2. Now, for each element of the array, intialize the struct data to all zeros.
    3. Before exiting the program, remember to free the pointer used to allocate dynamic memory

Created by Diana Palsetia