#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
最新推荐文章于 2025-01-12 21:18:39 发布
本文介绍了一个简单的字符串反转函数的实现方法。通过C语言编写,该函数可以将输入的字符串逐字符进行反转。代码中还包含了一个测试用例,用于验证反转函数的正确性。
859

被折叠的 条评论
为什么被折叠?



