1 2 3 4 5 6 7 8 9

If you want a "rat", compute H = 114+97+116 = 312
and then look in box 312 % 10 = 2.


There you will find a "cat", not a "rat" so look in box (2+1)
% 10 = 3, which is empty.


Therefore we have no rats here.


A possible structure to support this menagerie is:


#define M 10


typedef struct box* Boxptr;


typedefstruct box {
char* s;
}
Home;


If we wanted an array of these we would declare:
char* animal;
int i;
Boxptr p;
and set
p = (Boxptr) malloc (M*sizeof(Home));
and compute
i = Trans("dog") % M;
or perhaps
char animal[10];
scanf ("%s", &animal[0]);
i = Trans(animal) % M;
and to put the animal in its new home with:
(p+i)->s = animal;// or &animal[0]

February 15 1998

Page 7

TAM C201 notes