1、
#include <stdio.h> void put(char x[]) { int len = 0; while(x[len]) len++; int i; for(i = 0; i < len / 2; i++) { int tmp = x[i]; x[i] = x[len - 1 - i]; x[len - 1 - i] = tmp; } } int main(void) { char str[128]; printf("str: "); scanf("%s", str); put(str); int i = 0; while(str[i]) putchar(str[i++]); return 0; }
2、
#include <stdio.h> void put(char x[]) { int len = 0; while(x[len]) len++; char tmp[len]; int i = 0; while(x[i]) { tmp[i] = x[len - 1 - i]; i++; } i = 0; while(tmp[i]) { x[i] = tmp[i]; i++; } } int main(void) { char str[128]; printf("str: "); scanf("%s", str); put(str); int i = 0; while(str[i]) putchar(str[i++]); return 0; }