How do you reverse a string in C or C++ without requiring a separate buffer to hold the reversed string?
#include
#include
int main()
{
char *my_string = "THIS_IS_MY_STRING";
char *rev_my_string = my_string;
while (*++rev_my_string != '\0')
;
while (rev_my_string-- != (my_string-1))
{
printf("%c", *rev_my_string);
}
getchar();
return 0;
}
This is optimised code in the C language for reversing a string... And it is simple; just use a simple pointer to do the job...