In Class Week12

  1. Create a week12 subdirectory and copy over these file into it:
         cp /home/newhall/public/cs21/week12/* .
         

  2. Open up baby.c and implement the features described in the comments.

  3. Make a copy of baby.c
        cp baby.c babyarray.c
        

    In the copy, we really only need the definition of the babyType data structure.

  4. Change the program so that it now performs the following operations:

    1. Gets a filename from the user
    2. Opens the file
    3. Reads the first line of the file, and converts it to an integer. This will tell you how many baby data fields are in the rest of the file.
    4. Allocate space for an array of babyType of sufficient size.
    5. Create a function ReadBabyEntry that takes a file handle (FILE *) as a parameter and returns a babyType after reading the data from the file handle.

      a babyType is represented in the file by 4 lines

          BABY NAME
          LENGTH
          WEIGHT_LBS
          WEIGHT_OZ
          
      You probably will want to make use of the functions atoi() and atof().
    6. Iterate through the the allocated array and read in an entry using the previous function.
    7. Print out the values in your array.
    8. Don't forget to free() any space you malloc(). You should run your program using valgrind to check.

  5. If you have time, write functions that take an array of babyType and its length as parameters and calculates

    1. The biggest baby
    2. The smallest baby
    3. The longest baby
    4. The shortest baby