please post code so we don't have to guess what you are doing. But basically its like this
char string[] = "Hello World";
int len = strlen(string)-1;
while(len >= 0)
printf("%c",string[len--]);
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
strcpy() function does not take 3 parameters --
strcpy(reversedUserInput, userInput);
>>for (reversedUserInput; i >= 0; i--)
This is incorrect. you have to initialize variable i with the length of reversedUserInput string minus 1 (because of null terminator)
for (i = strlen(reversedUserInput)-1; i >= 0; i--)
>>cout << "The string reversed:\n" << reversedUserInput << endl
This is incorrect too. It will display the entire string in normal order (not reverse order). It should print just one character on each loop iteration.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
here is how I would code it.
cout << "The string reversed: ";
for (i = strlen(reversedUserInput)-1; i >= 0; i--)
{
// print the <strong>ith</strong> character
cout << reversedUserInput[i];
}
cout << "\n";
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343