请编写程序,用函数实现功能:把s所指字符串中的内容逆置。例如:字符串中原有的字符串为:abcdefg,则执行后, 串s中的内容为:gfedcba。
请编写程序,用函数实现功能:把s所指字符串中的内容逆置。例如:字符串中原有的字符串为:abcdefg,则执行后, 串s中的内容为:gfedcba。#include <stdio.h> void fun(char *s,int n) { if(1 == n || 0 == n) return ; char temp = s[n-1]; s[n-1] = s[0]; s[0] = temp; fun(s+1,n-2); } int main(int argc, _TCHAR* argv[]) { char a[] = "abcdefg"; fun(a,7); puts(a); return 0; }给你写个犀利的字符串逆转
#include <stdio.h> int main(void) { char str[] = "beautiful"; int i = 0, j = sizeof(str) / sizeof(char) - 2; while(i < j) { str[i] ^= str[j]; str[j] ^= str[i]; str[i] ^= str[j]; i++; j--; } printf("%s\n", str); return 0; }