小白学c语言,求解用栈判断回文字符串,错在哪里,急求

qq_40478118 qq_40478118 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#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");
}
}
...全文
评论 3
收藏 已收藏
分享
返回顶部
qq_40478118
新手乐园 33,315 成员 41,769 内容