CISC105 Fall 2006 Lab11 CISC105 Fall 2006 Lab11

Programs

  1. Define a struct type Dog that stores number of legs, weight, name, and breed. Write a function that prints a single Dog. Then declare and print the dogs 3-legged Sadie, a 55 lb poodle, and Rosie, a four-legged 123.6 lb Neopolitan Mastiff.

  2. Declare an array of 10 Dogs1. Make up data in a data file and read all ten dogs into your array of structs. Find the lightest Dog in the array and print it with an appropriate message. Find the Dog in the array with the first alphabetical name and print it with an appropriate message.

  3. Declare an array of char and initialize it to a phrase with at least five words, separated by spaces and/or commas. Use a loop and strtok to print the five words separately.

  4. Read the file "lab11.txt" one line at a time, and use strtok to get individual words. Write a function that counts the number of occurences of a C-string parameter in a line, and returns the count. For example, you might call the function with the word "Dog" and the line you just read. Your program will take a single word as a command line argument and print the total number of times the word appears in the data file.

  5. Use malloc to allocate space for a single integer in memory. Put a number in the space, and then print the number from the space.

You should have a total of 5 programs named lab11.1.c to lab11.5.c. Make a single script file (see lab00 for the instructions) where you cat, compile, and run each one in its final form.

Submit all C files and your script on WebCT, and give the paper version of the complete script file only to your TA at the beginning of your next lab (all Friday labs) or in lecture Friday (Wednesday labs only). Note: Cat, compile, and run each program in order! Do not cat all programs, then compile, etc.

Footnotes:

1If you are bored you can make some type besides dogs, e.g. professors. Must have at least four data values of various types.


File translated from TEX by TTH, version 3.38.
On 15 Nov 2006, 07:40.