CS-211 Fall 2015 Lab 7 Arrays and Pointers


We learned in lecture on Monday that arrays and pointers are really the same thing. Today we get to prove it. Today we are going to write two implementations of the string comparison function, strcmp, one using array notation, and another using pointer notation.

One more background item to cover... how we compare two strings. For this lab, we will use the same conventions used in the standard libray function, strcmp to compare two strings. If you compare the character vector in a to the character vector in b, you should return -1 if a is less than b, zero if a equals b, and +1 if a is greater than b. The only case in which a equals b is if a and b are the same length, and every character in a exactly matches the corresponding character in b. If two strings are not equal, then they may share an equal prefix string, but after that prefix, there is at least one character that is different between a and b. We determine whether a is less than b or a is greater than b based on the first differing character. If that first differingg character in a is less than the corresponding character in b, using the ASCII character codes, then the string in a is less than the string in b. If the first differing character is greater, then a is greater than b.

Getting Started

Download the code that has been started for you in lab7.tar.gz. Use the command tar -xvzf lab7.tar.gz. This will unpack the tar file and make a new lab7 subdirectory. The lab6 directory will have a Makefile, and the C code to start from in file compStr.c

The compStr.c File

The compStr.c file starts of with the standard includes for standard library functions, and prototypes for the three lower level functions in the file.

What follows is just the normal function definitions that we are used to seeing. I've included a description of each of these functions below.

Using The Makefile

The Makefile file in the lab7 directory contains "targets" which allow you to do several things using the make command. The following targets are supported:

Lab Report

Download and edit the following file: lab7_report.txt. Then submit your editted file on Blackboard in the Lab_07 report area.