Make a reverse copy of a string. - C++ Data Type

C++ examples for Data Type:char array

Description

Make a reverse copy of a string.

Demo Code

#include <iostream>
#include <cstring>
using namespace std;
void revstrcpy(char *rstr, const char *orgstr) {
   rstr += strlen(orgstr);/*from  ww w . j a v a  2  s  .c  o m*/
   *rstr-- = '\0';
   while(*orgstr)
      *rstr-- = *orgstr++;
}
int main() {
      char str[5] = "abcd";
      char rev[5];
      revstrcpy(rev, str);
      cout << rev;
      return 0;
}

Result


Related Tutorials