C++面试常见问题——05字符串的逆序

字符串的逆序

#include<iostream>
#include<string.h>
using namespace std;

void ReverseStr(char s[]){
    int i,j;
    char tmp;
    for(i = 0,j = strlen(s)-1;i < (strlen(s)/2);i++,j--){
        tmp = s[i];
        s[i] = s[j];
        s[j] = tmp;
    }
    return ;
}
int main(){
    char s[] = "faohjgahoih";
    ReverseStr(s);
    return 0;
}
posted @ 2020-02-23 14:36  MenciusYue  阅读(615)  评论(0)    收藏  举报