请编写一个函数fun(char *s),该函数的功能使把字符串中的内容反转。
请编写一个函数fun(char *s),该函数的功能使把字符串中的内容反转。
#include <stdio.h>
#include <string.h>
void fun(char *s) {
int len = strlen(s);
int i, j;
char temp;
for (i = 0, j = len - 1; i < j; i++, j--) {
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
}
int main() {
char str[] = "Hello, World!";
printf("原始字符串: %s\n", str);
fun(str);
printf("反转后的字符串: %s\n", str);
return 0;
}