C Basics Exercises

To access the starter code for these exercises, use the following command:

git clone /afs/ir/class/archive/cs/cs107a/cs107a.1224/WWW/exercises/cbasics

For solutions, see the _soln.c versions of the C files.

p1 (argv/printf)

Garfield is a fat cat that only eats lasagna. Write a C program in garfield.c that checks whether all command-line arguments passed are the word "lasagna", and prints "Yum, I found n lasagna!" (where n is the number of arguments) if so, and "Lasagna and only lasagna" otherwise.

The is_lasagna function is provided since we haven't learned how to compare strings in C yet.

Note that there must also be at least one "lasagna" argument - passing zero arguments shouldn't suffice.

Some test cases to try: