我的教授要求我们使用栈来检查一个单词是否是回文。每次运行时,都会出现错误:Unhandled Exception. Access violation
。我做错了什么?如何改进我的代码?以下是我的代码:
typedef struct stack{
char name;
struct stack * next;
}Stack;
void push(Stack**head, char value);
char pop(Stack**head);
int main(){
char word[11];
int i=0;
int lenght = 0;
Stack*head = NULL;
printf("Please type the word: ");
scanf("%s", word);
lenght = strlen(word);
while(word[i]!='\0'){
push(&head, word[i]);
i++;
}
i = 0;
while(pop(&head)==word[i]){
i++;
}
if(i==lenght) printf("The word is a palindrome");
else printf("The word is not a palindrome");
}
value
иҖҢдёҚжҳҜvalue[i]
гҖӮ - ruslik