字符串反转 C++实现,不使用系统函数:

// ReverseString.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
using namespace std;

char* ReverseString(char* str)
{
    char* p = str;
    char* q = str;
    char temp;
    
    while(*q != NULL && *q != '\0')
    {
        q ++;
    }
    q --;
    while(p < q )
    {
        temp = *p;
        *p = *q;
        *q =  temp;
        p ++;
        q --;
        
    }
    return str;
}
int _tmain(int argc, _TCHAR* argv[])
{
    char str[] = "123456789";
    cout << ReverseString(str) << endl;
    cin.get();
    return 0;
}

 

相关文章:

  • 2021-10-03
  • 2021-11-28
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-28
  • 2021-07-28
  • 2021-09-06
  • 2021-10-13
  • 2022-12-23
  • 2021-06-15
  • 2021-12-27
相关资源
相似解决方案