#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct hui{
char *data;
int top;
} *Hui;
int IsHui(char *s);
void main() {
char c[100];
printf("Enter:\n");
gets(c);
if(IsHui(c))
printf("Is\n");
else
printf("NO\n");
}
int IsHui(char *s) {
int n = strlen(s);
Hui S = (Hui)malloc((n/2)*sizeof(char)+sizeof(int));
S->top = -1;
for(int i = 0; i < n/2; i++) {
S->top++;
S->data[i] = s[i];//这一步使程序停止????为什么???
}
char temp;
i = i - 1;
while(S->top>=0) {
temp = S->data[i];
if(temp != s[n-i-1])
return 0;
i--;S->top--;
}
return 1;
}
这是我的回文游戏.为什么S->data[i] = s[i];这一步对结构体中的数组赋值运行不了???晕~~~