Reverse String C++ using char array

前端 未结 5 628
暖寄归人
暖寄归人 2020-12-03 01:52

I wrote a simple C++ program to reverse a string. I store a string in character array. To reverse a string I am using same character array and temp variable to swap the char

5条回答
  •  臣服心动
    2020-12-03 02:20

    //reverse a string
    #include
    using namespace std;
    
    int strlen(char * str) {
      int len = 0; 
      while (*str != '\0') {
        len++;
        str++;
      }
      return len;
    }
    
    void reverse(char* str, int len) {
      for(int i=0; i

提交回复
热议问题