1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include <stdio.h> #include <stdlib.h> #include <string.h> void main() { char s[20]; printf("word ? "); scanf("%19s", s); int len = strlen(s); char *line = (char *)malloc(sizeof(char) * 2 * len); int i; for (i = 0; i < 2 * len - 1; i++) line[i] = ' '; line[i] = '\0'; char *p, *q; p = q = line + (len - 1); for (i = 0; i < len; i++) { *p-- = *q++ = s[i]; printf("%s\n", line); } free(line); }