#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() function
int 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;
}
reverse函数 倒置字符串各个字符位置 3.5
最新推荐文章于 2023-12-01 10:46:27 发布