您的位置:首页 > 其它

自编strlen()函数,并用它递归调用编写revers(S)函数,给字符串S倒序

2009-07-27 14:59 295 查看
#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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐