小白学c语言,求解用栈判断回文字符串,错在哪里,急求
#include<stdio.h>
#include<malloc.h>
#include<string.h>
#define M 100
typedef struct stack
{
char data[M];
int top;
}node;
void ruzhan(node &s,char x)
{
if(s.top==M)
{
printf("栈空\n");
return;
}
else
{
s.data[s.top]=x;
s.top;
}
}
char chuzhan(node &s)
{
if(s.top==0)
{
printf("栈空\n");
return '0';
}
else
{
return s.data[--s.top];
}
}
void main()
{
int i=0;
char a[M]="\0",b[M]="\0";
node head={"\0",0};
printf("input :");
gets(a);
while(a[i]!='\0')
{
ruzhan(head,a[i]);
i++;
}
i=0;
while(head.top!=0)
{
b[i]=chuzhan(head);
i++;
}
b[i]='\0';
i=0;
while(b[i]!='\0')
{
printf("b[]=%c\n",b[i]);
i++;
}
if(strcmp(a,b)==0)
{
printf("yes\n");
}
else
{
printf("no\n");
}
}
#include<malloc.h>
#include<string.h>
#define M 100
typedef struct stack
{
char data[M];
int top;
}node;
void ruzhan(node &s,char x)
{
if(s.top==M)
{
printf("栈空\n");
return;
}
else
{
s.data[s.top]=x;
s.top;
}
}
char chuzhan(node &s)
{
if(s.top==0)
{
printf("栈空\n");
return '0';
}
else
{
return s.data[--s.top];
}
}
void main()
{
int i=0;
char a[M]="\0",b[M]="\0";
node head={"\0",0};
printf("input :");
gets(a);
while(a[i]!='\0')
{
ruzhan(head,a[i]);
i++;
}
i=0;
while(head.top!=0)
{
b[i]=chuzhan(head);
i++;
}
b[i]='\0';
i=0;
while(b[i]!='\0')
{
printf("b[]=%c\n",b[i]);
i++;
}
if(strcmp(a,b)==0)
{
printf("yes\n");
}
else
{
printf("no\n");
}
}
...全文


新手乐园
