回车后肿么终止不了啊(回文序列栈实现)
while(c!=13);怎么不起作用呢程序代码:
#include<stdio.h> #include<stdlib.h> #include<conio.h> #include<malloc.h> #include<ctype.h> typedef struct Stack { char info; struct Stack *next; }Stack; Stack *start; Stack *rstart; Stack *cstart; Stack *push(Stack *); Stack *pop(Stack *); char peer(Stack *); int isaplha(char c) { if((('a'<=c)&&(c<='z'))||(('A'<=c)&&('Z'>=c))&&(c!=32)) return 1; else return 0; } char peer(Stack *rec) { if(rec=NULL) printf("Stack is empty."); else return rec->info; } int isempty(Stack *rec) { if(rec=NULL) return 1; else return 0; } Stack *push(Stack *rec,char info) { Stack *new_rec; new_rec=(Stack *)malloc(sizeof(Stack)); new_rec->info=info; new_rec->next=rec; rec=new_rec; } Stack *pop(Stack *rec) { Stack *temp; if(rec==NULL) printf("Stack is empty."); else { temp=rec->next; free(rec); rec=temp; } return rec; } int main() { char c; int flag=0; printf("Enter the characters :\n"); do { scanf("%c",&c); if(isaplha(c)) { start=push(start,c); cstart=push(cstart,c); } }while(c!=13); while(!isempty(start)) { rstart=push(start,peer(start)); start=pop(start); } while(!isempty(rstart)) { if(toupper(peer(rstart))==toupper(peer(rstart))) flag=1; else { flag=0; break; } } if(flag==1) printf("The string is a palindrome"); else printf("The string is not a palindrome"); system("pause"); }