标题:edit函数出问题,读入字符的循环进不去
只看楼主
liyangy
Rank: 2
等 级:论坛游民
帖 子:6
专家分:10
注 册:2010-1-29
结帖率:50%
已结贴  问题点数:20 回复次数:1 
edit函数出问题,读入字符的循环进不去
#include "stdio.h"
#include "stdlib.h"
#define NULL 0
#define TRUE 1
#define MAXSIZE 100
typedef char datatype;
typedef struct
{
   datatype stack[MAXSIZE];
   int top;
}seqstack;

seqstack *s;

void INITSTACK(seqstack *s)
{  
  s->top=-1;
}

int EMPTY(seqstack *s)
{
   if(s->top <0)
       return TRUE;
   else return NULL;
}

seqstack *push(seqstack *s,datatype x)
{
    if(s->top ==MAXSIZE-1)
    {    printf("the stack is full\n");
        return NULL;
    }
    else
    {
       s->top++;
       s->stack[s->top]=x;
    }
    return s;
}

datatype pop(seqstack *s)
{
  datatype x;
  if(EMPTY(s))
  {
     printf("the stack is empty\n");
         return NULL;
  }
  else
  {
    x=s->stack[s->top];
    s->top--;
  }
  return x;

}

void edit()
{
  char c,name[80];
  int k=0;
  printf("input char as * to end\n");
      c=getchar();
  name[k++]=c; printf("%d\n",100);
  while(c!='*')
  {
     if(c=='#')
         pop(s);
     if(c=='@')
         INITSTACK(s);
     else push(s,c);
     c=getchar();
     name[k++]=c;
   
  }
  name[k++]='\0';
  k=0;
  printf("you input char is:\n");
while(name[k]!='\0')
 printf("%c  ",name[k++]);
}

void main()
{  s=(seqstack *)malloc(sizeof(seqstack));
    char c;
    edit();
    printf("output char:\n");
    while(EMPTY==0)
    {
       c=pop(s);
       printf("%c  ",c);
    }
    printf("\n\n");
    getchar();

}
搜索更多相关主题的帖子: 字符 edit 
2010-02-12 01:48
heartnheart
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:335
专家分:1096
注 册:2009-7-10
得分:20 
void main()
{  s=(seqstack *)malloc(sizeof(seqstack));
   char c;
    edit();
    printf("output char:\n");
    while(!EMPTY(s))//改成这样就行了
    {
       c=pop(s);
       printf("%c  ",c);
    }
    printf("\n\n");
    system("pause");

}
另外,你定义的NULL和系统的冲突,得注意
2010-02-14 19:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-297609-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018976 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved