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

来源:互联网 发布:程序员上线烧香图片 编辑:程序博客网 时间:2024/04/30 07:01

#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);
}

原创粉丝点击