改进一下用字符数组实现,字符串长度有限制#include<conio.h> #include<stdio.h> int main(void) { int i; int ch[128]; for (i = 0; (ch[i] = getchar()) != '\n'; i++);printf("\n");for (; i >= 0; i--) printf("%c", ch[i]);getch(); return 0; }在 TC 上测试通过用链表实现,动态存储,字符串长度无限制#include<alloc.h>#include<conio.h>#include<stdio.h>#include<stdlib.h>#define TYPE struct ch#define LEN sizeof(struct ch)int main(void) { TYPE { char c; TYPE *previous; TYPE *next; }; TYPE *head, *last; TYPE *p, *q; head = (TYPE *)malloc(LEN); p = head; q = NULL; printf("Input a string : "); if ((head->c = getch()) != '\r') do { if (p->c != '\b') { printf("%c", p->c); p->previous = q; q = p; p->next = (TYPE *)malloc(LEN); p = p->next; } else { if (q != NULL) { free(p); p = q; q = p->previous; printf("\b \b"); } } } while((p->c = getch()) != '\r'); p->previous = q; p->next = NULL; last = p; printf("\n\nThe string inputed is : "); q = last->previous; while (q != NULL) { printf("%c", q->c); q = q->previous; } getch(); return 0;}在 TC 上测试通过