Summary: In this laboratory, you will experiment with C's strings and the various standard string procedures.
Create a new directory for this laboratory.
Consider the following two mechanisms for printing the string
a. Which do you prefer? Why?
b. Write a simple program in which the two statements have different output.
Here are a number of different string declarations.
char *baboon; char *chimpanzee = "animal"; char dolphin; char emu = "animal"; char fox; char fox = "animal";
a. Which are valid and which are invalid?
b. How do the valid declarations differ?
a. Consider the following declaration and code
char gorilla; char ch; ... printf("sizeof(gorilla): %d\n", sizeof(gorilla)); printf("strlen(gorilla): %d\n", strlen(gorilla)); printf("gorilla: '%s'\n", gorilla);
What do you expecct the output to be?
b. How would your answer change if
gorilla were declared with
c. Verify your hypotheses experimentally.
d. What do your results suggest?
iguana are both
declared as strings. When, if ever, is
iguana = hippo;
a valid assignment?
Note that you may need to try different kinds of declarations.
Consider the folling declarations:
char jackal = "animal"; char koala = "animal"; char lemur = "animal";
a. What do you expect the effect of the following instruction to be?
b. Verify your answer experimentally. Make sure to print out all three strings.
c. Explain your answer.
d. Assume you didn't execute the instruction from step a. What do you expect the effect of the following instruction to be?
e. Verify your answer experimentally. Make sure to print out all three strings.
f. Explain your answer.
Write a procedure,
char *reverse(char *str),
that reverses the order of characters in
str and returns
the modified str. Your procedure should modify
Write a program that implements the Name Game.
Thursday, 13 February 2003 [Samuel A. Rebelsky]
Friday, 14 February 2003 [Samuel A. Rebelsky]
I usually create these pages
on the fly, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Fri May 2 14:19:58 2003.
The source to the document was last modified on Fri Feb 14 15:47:17 2003.
This document may be found at