自编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);
}
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);
}
相关文章推荐
- 用递归的方法编写函数求斐波那契级数,观察递归调用的过程
- 运用递归编写strlen函数实例
- 练习 4-12 运用 printd 函数的设计思想编写一个递归版本的 itoa 函数,即通过递归 调用把整数转换为字符串
- 编写一个递归调用函数,输出vector对象的内容
- 编写一个函数,当n为偶数的时候,输入n偶数是调用1/2+1/4........当n为奇数的时候调用1/1+1/3+1/5
- 编写函数,其功能是:将一个数字字符串转换为一个整数(不得调用C语言中提供的将字符串转换成整数的函数。)要求在主函数中输入该字符串并输出转换后的整数的值。
- python调用matlab编写的函数
- 编写一个函数实现n^k,使用递归实现
- 《叩响C#之门》第6章 函数 6.5 递归调用(生日贴)
- C++ Primer 学习笔记_22_函数(续1) --return语句、递归调用、函数声明
- 编写LUA 可调用的C 函数技巧
- 编写一个函数reverse_string(char * string)(递归实现)
- [Effective C++ --005]了解C++默默编写并调用哪些函数
- 条款5:了解C++默默编写并调用哪些函数(Know what functions C++ silently writes and calls)
- 递归调用实例分析2.在函数中间的递归与在函数尾部的递归
- 编写求两个整数最大公约数的函数,并调用此函数求两个整数的最大公约数?
- 如何在C语言中调用C++编写的DLL中的函数
- Effective C++学习笔记 条款05:了解C++默默编写并调用的哪些函数
- 爬楼梯——递归与函数自调用算法
- (4)了解C++默默编写并调用了哪些函数