Assignment on string handling and arrays. Due Wednesday Nov 14, 2001

 

We already know how to read a string by using the syscall.  Note that such a string will be null-terminated.

We have also seen how to copy a string.  Now we want to use these ideas in the following two assignments.

 

1.       Read in a string and then output it both backwards and forwards.

 

E.g. A test of a program I wrote in C had this screen dump:

 

String? This is a string.

This is a string.

.gnirts a si sihT

 

We can put this in a loop and do it for several strings before stopping.  How should we end this loop?  A good way would be to test for the string “end”.  Another (perhaps easier) way would be to use any string beginning with a non-letter as a terminator.

 

 

2.       Test whether or not a given string is a palindrome.

 

This problem can be done on several levels.  Here are some suggestions.  (Level A is the minimum requirement.)

 

A.      Test lines with no spaces and all lower case.  So we would find that “refer” and “amanaplanacanalpanama” are both palindromes.

B.       Allow spaces and punctuation on input.  Then remove the spacing and punctuation and test.  This would find that “stressed? desserts” is a palindrome.

C.       Allow upper and lower case letters, spaces, and punctuation.  This would find “Too hot to hoot.”  (said by an owl on a warm night) to be a palindrome.