Guest User

Untitled

a guest
Jan 22nd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  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]);
Add Comment
Please, Sign In to add comment