【C语言】编写一个函数reverse_string(char * string) 实现:将参数字符串中的字符反向排列。要求:不能使用C函数库中的字符串操作函数。

来源:互联网 发布:app用户表数据库设计 编辑:程序博客网 时间:2024/05/29 17:41
// 编写一个函数reverse_string(char * string)//实现:将参数字符串中的字符反向排列。//要求:不能使用C函数库中的字符串操作函数。#include <stdio.h>int main (){void reverse_string(char * str);    char s[] = "doudouwa";  printf("%s\n",s);     reverse_string(s);    printf("%s\n",s);  return 0;}void reverse_string(char * str){char temp;int i,j;for(i=0;  ;i++){if(*(str+i)=='\0')break;}   //求字符串长度i--;for(j=0;j<=i;i--,j++){temp=*(str+j);*(str+j)=*(str+i);*(str+i)=temp;}   //字符串翻转} 
<img src="http://img.blog.csdn.net/20150325174901474?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZG91ZG91d2ExMjM0/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />

0 0