Strings
- Strings are arrays of characters in C++
- See the program flipper.cpp for an example of string manipulation
- The program takes the string s1 as input, sends it to a function
called flip to reverse it. Outputs the original and reversed string
- To start with we only wrote the driver program and the function
flip was written as a stub
- A stub is a function with some trivial output statement in
the body of the program
- Writing drivers and testing them with stubs allows us to make
sure that the skeleton of the program is properly written and
free of errors
- After the driver with stubs is tested, we go ahead and add
the body of the stubs
- Note that the function flip has two parameters
- both are arrays of characters
- source is passed as const to make sure that the source is
not inadvertantly changed. The compiler will report an error message
if you try
- Another new feature we looked at was declaration of variables
in the middle of a function.
- Sometimes it is a good practice to declare variables just
before they are used. See variable s2 in flipper.cpp.