Fixing Errors

This is a pair exercise and must be competed in your tutorial or lab with your partner.

You should make sure you have completed bird is the word before completing this task.

Copy the program kangaroo.c from the course account to your directory by typing (make sure you type the dot at the end):

$ cp /web/cs1511/17s2/week01/files/kangaroo.c .

The dot ‘.’ is a shorthand for the current directory and there is a space between kangaroo.c and the next dot. You can check that the file has been copied by typing:

$ ls
bad_pun bad_pun.c bird bird.c kangaroo.c

You can examine the contents of the file by typing:

$ less kangaroo.c
// A simple C program that prints an ASCII kangaroo
// Written 7/3/2017
/  by Andrew Taylor (andrewt@unsw.edu.au)
// as a lab example for COMP1511
...

(less is an improved version of an earlier utility called more, which shows you long text files one page at a time and allows you to go forward and back using the space bar and the ‘B’ key. Less is more! Press ‘q’ to exit less.)

Now try to compile kangaroo.c. You should see a list of confusing error messages.

$ dcc -o kangaroo kangaroo.c
kangaroo.c:4:1: error: expected identifier or ?(? before ?/? token
 /  by Andrew Taylor (andrewt@cse.unsw.edu.au)
...

Your job is to fix the errors.

You’ll need to use an editor to change the file kangaroo.c

Run gedit like this:

$ gedit kangaroo.c &

When you have fixed all the errors you should be able to do this.

$ dcc -o kangaroo kangaroo.c
$ ./kangaroo

  /\   ___
 <__\_/    \
    \_  /  _\
      \_\ / \\
        //   \\
      =//     \==

Hint: the error messages are confusing but they usually indicate where the problem is.

Hint: treat it as a puzzle. Look for differences between your program and the working programs you have been shown.

Hint: all the errors but one involve a single missing character.

Hint: if it looks like there are too many backslashes in the program, it is correct. Don’t delete any backslashes (you do need to add one backslash). It was mentioned in lectures that the backslash has a special interpretation in C.

To run some simple automated tests:

$ 1511 autotest kangaroo

To run Styl-o-matic:

$ 1511 stylomatic kangaroo.c
Looks good!

You’ll get advice if you need to make changes to your code.

Submit your work with the give command, like so:

$ give cs1511 wk01_kangaroo

Or, if you are working from home, upload the relevant file(s) to the wk01_kangaroo activity on Give Online.