daily pastebin goal
42%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void reverse (char* str) {
  2.     char* newStr = (char*)malloc(sizeof(str));
  3.  
  4.     for (int i=0;i<sizeof(str)/sizeof(char);i++) {
  5.        int index = sizeof(str)/sizeof(char)-1-i;
  6.        newStr [i] = str [index];
  7.     }
  8. }
  9.    
  10. void reverse (char* str) {
  11.    size_t len = strlen(str);
  12.    char* newStr = (char*)malloc(len + 1);
  13.  
  14.    for (int i=0; i<len;i++) {
  15.       int index = len-1-i;
  16.       newStr[i] = str[index];
  17.    }
  18.    newStr[len] = ''; // Add terminator to the new string.
  19. }
  20.    
  21. std::string reverse(std::string str) {
  22.   for (std::string::size_type i = 0, j = str.size(); i+1 < j--; ++i) {
  23.     char const swap = str[i];
  24.     str[i] = str[j];
  25.     str[j] = swap;
  26.   }
  27.   return str;
  28. }
  29.    
  30. void reverse(char (&str)[10]);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top