#include <iostream>
using namespace std;
int strlen1(char *p)
{
int i=0;
while ( (*p)!=NULL )
{
p++;
i++;
}
return i;
}
void revers(char *p)
{
char s1[100]="";
int len;
while ( (*p)!=NULL )
{
len=strlen1(p);
s1[len-1]=*p;
p++;
}
cout << s1 << endl;
}
void main()
{
char str1[100]="";
cout << "Input string:";
cin >> str1;
cout << "The string length is:" << strlen1(str1) << endl;
revers(str1);
}
本文介绍了一个简单的C++程序,该程序实现了字符串长度的计算及字符串的反转功能。通过使用指针遍历字符数组来实现这些功能,展示了基本的字符串操作技巧。
1062

被折叠的 条评论
为什么被折叠?



