@
kempofighter
Why not help him satisfy the requirements of his homework? He needs to do the reverse function himself, using simple arrays.
@
usafsatwide
On line 18 you have a single
character named 'stringReverse'. It does not matter what you
name a thing, its
type is what matters. In this case, you have only one character, which is not a string. A string is many characters, like you have on line 31, where you declare an array of INPUT_SIZE characters.
If I may, however, your function to reverse strings should not perform any output, it should simply reverse the string given to it.
1 2 3 4 5 6 7
|
void reverseString( char* s )
{
// This functions reverses the order of the chars in s.
// You only need two things: the length of the string and an index into
// the string from either end.
...
}
|
Then you can use it simply:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
int main()
{
const int INPUT_SIZE = 80;
char input[INPUT_SIZE];
//Get the user's desired string
cout << "Please enter a phrase or sentence: \n\n";
cin.getline(input, INPUT_SIZE); //Read input as a string
cout << "The number of characters in your string is: " << stringLength(input) << ".\n";
reverseString(input);
cout << "The reversed string is: " << input << endl;
return 0;
}
|
One more thing to notice: you have defined a function to determine the length of a string
stringLength(), but instead of using it properly, you use
strlen() and have your function do what it is supposed to: count the number of characters in the string and return that value.
Hope this helps.
[edit] Well, get called away for a moment and the conversation misses me... [/edit]