注册 登录
编程论坛 C++教室

这是一个回文的程序,自己编的,可出现了好多问题, 我想让高手指点哈!

王一南 发布于 2011-03-30 12:35, 551 次点击
#include<stdio.h>
#define num 20
typedef struct
{
  char elem[num];
  int top,r,p;
}seqstack;

int main()
{ int i,j,m,n;
  seqstack s;
  char c;
  s->top=-1;
  printf("Please input the num of the First sequence:");
  scanf("%d",&n);
  for(i=1;i<=n;i++)
  {printf("Please input the characer:");
   c=getchar();
   if(c='&') continue;
   s->top++;
   s->elem[s->top]=c;
   p=s->top;
  }
  s->top=s->top++;
  s->elem[s->top++]='&';
  r=s->top++;
  printf(" input the number of the Second characters:");
  scanf("%d",&m);
  if (m!=n) return(ERROR);
  for(j=1;j<=m;j++)
  {printf(" input the character:");
   c=gecher;
   if(c='&')  continue;
   s->top++;
   s->elem[s->top]=c;
  }
    match(p,r);
    return(match);
}
 int match(int *p,int *r)
 {while(s-p!=0)
  if(s->elem[s->p]==s->elem[s->r])
  {s->p--;
   s->r++;
   return (TRUE);
  }
  else
      return(FALSE);

 }
8 回复
#2
hellovfp2011-03-30 13:05
问题描述呢?
#3
王一南2011-03-30 17:43
回复 2楼 hellovfp
问题就是两个指针*p和*r不知道在那进行定义!那个栈定义应该是seqstack *s;
#4
lucky5635912011-03-31 07:58
何必用这种方法
#5
王一南2011-03-31 09:25
回复 4楼 lucky563591
那这种方法应该怎么改正!
#6
Ben22122011-03-31 16:11
说实话,你这个程序很乱,而且条理不是很清楚,对于r和p,我觉得你有些糊涂了,究竟是指针,还是结构体里的变量,你应该分清楚!
#7
王一南2011-03-31 22:06
回复 6楼 Ben2212

现在运行就是这个问题,不知道应该怎么改正!
#8
hellovfp2011-04-01 12:14
出现的问题不是一点的多,是太多了。
分不清哪里是指针,哪里是结构,哪里是结构变量,函数里凭空就出现未定义变量使用,ERROR这些哪里定义过?return match?match倒底是变量还是函数返回值??思路一片混乱。
自己好好整理一下思路,重写,并写注释!解释每一行的变量或是运算符要做什么?代表什么意思?


[ 本帖最后由 hellovfp 于 2011-4-1 12:18 编辑 ]
#9
Ben22122011-04-01 12:26
你把你的思路说出来看看,回文为什么会用到结构体?以及结构体该怎么用,都写出来,好让大家帮你想办法
1