编写函数将字符串按逆序存放

来源:互联网 发布:linux下中文显示乱码 编辑:程序博客网 时间:2024/06/06 05:36
#include<iostream>
#include<windows.h>
#include<string.h>
using namespace std;
int reversalstr(char *p)
{
int count = strlen(p);
char temp;
cout << count;
for (int i = 0; i < count / 2; i++)
{
temp = p[i];
p[i] = p[count - i-1];
p[count - i-1] = temp;
}
//p[0] = p[2];
return 0;
}
int main()

{

        char  pstr[30];

cout << "请键入字符串:"<<endl;
cin >> pstr;
cout << "\n" << "字符串:" << pstr<< endl;
reversalstr(pstr);
cout << "\n" << "字符串:" << pstr<< endl;


system("pause");


}
0 0
原创粉丝点击