reverse函数 倒置字符串各个字符位置 3.5

来源:互联网 发布:网上买菜 知乎 编辑:程序博客网 时间:2024/04/28 20:59
#include<ctype.h>#include <stdio.h>#include <string.h>/* reverse function,reverse every char in the sting s*/void reverse(char s[]){//remember the strlen() functionint j=0;int tmp;printf("\nlll");//the fist time  I code like this:for(int i=strlen(s)-1;i!=j;)for(int i=strlen(s)-1;i>j;){printf("\nfor");tmp=s[j];s[j++]=s[i];s[i--]=tmp;}}int main(){//test and I always forget add ";" in the end,becareful;char s[]="hello sister huang";reverse(s);printf("\n%s",s);return 0;}

0 0
原创粉丝点击