逆序输出字符串
//
// main.cpp
// daxuejisuanji
//
// Created by fyr on 2019/12/26.
// Copyright © 2019年 fyr. All rights reserved.
//
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char str[20];
cout<<"请输入字符串:"<<endl;
cin>>str;
//cout<<endl;
int len=0;
while (str[len]!='\0') {
len++;
}
cout<<"长度="<<len<<endl;
cout<<str<<endl;
int i=0,j;
char sub[20];
for (j=len-1; j>=0; j--) {
sub[i]=str[j];
i++;
}
sub[i]='\0';
cout<<"sub="<<sub<<endl;
return 0;
}
Output
请输入字符串:
aad
长度=3
aad
sub=daa
Program ended with exit code: 0
来源:CSDN
作者:weixin_44688377
链接:https://blog.csdn.net/weixin_44688377/article/details/103951525