#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void my_str(char* str)
{
int len = strlen(str);
int i = 0;
char c;
for (i = 0; i<len/2; i++)
{
//交换字符
c = str[i];
str[i] = str[len-i-1];
str[len-i-1] = c;
}
}
void my_str1(char* str)
{
int i = 0;
int len = strlen(str);
char *dest = malloc(len+1);
memset(dest, 0x00, len+1);
for (i = 0; i<len; i++)
{
dest[i] = str[len-i-1];
}
strcpy(str, dest);
free(dest);
}
int main()
{
char p[6] = "abcd";
my_str1(p);
printf("%s\n", p);
return 0;
}
linux c字符串逆转
最新推荐文章于 2023-01-17 22:12:39 发布