【发布时间】:2011-05-24 12:02:48
【问题描述】:
我们的教授要求我们使用堆栈来检查一个单词是否是回文。
每次运行都会报错: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]。
标签: c data-structures palindrome stack