Can somebody tell me a simple function of reversing an inputed string?
Can somebody tell me a simple function of reversing an inputed string?
Which string class are you using??? <string.h> or <apstring.h> ???
<^>( * ; * )<^>
If you're using <string.h> :
#include <string.h>
char *Reverse(char *string)
{
int min = 0;
int max = strlen(string)-1;
char temp;
while(min<max)
{
temp = string[min];
string[min] = string[max];
string[max] = temp;
min++;
max--;
}
return string;
}
ok, here we go again. use strrev().
Code:#include<iostream.h> #include<string.h> int main() { char string_to_reverse[255]; cout<<"Enter a string to reverse.\n". cin.getline(string_to_reverse, 255, '\n'); cout<<"String before reversal. "<<string_to_reverse<<"\n"; strrev(string_to_reverse); cout<<"String after reversal. "<<string_to_reverse<<"\n"; return 0; }
Sometimes, the farthest point from the center is the center itself.
Your life is your canvas, it's only as beautiful as you paint it.
yup string.h