请帮忙看看这个程序的运行结果为何这样怪

    请高手帮我看看这个程序为何不能正常运行。程序的目的是对输入的C语言声明进行解释,如输入 char **p   应该显示 p: pointer to pointer to char 输入 int *daytab【13】应该显示 daytab: array[13] of pointer to int 运行后前者能正常运行但后者却没有任何显示,在输入 int *daytab【13】后回车就不执行,等了很长时间也没有反应,不知道为何,呼吁高手帮忙解决,在此先行谢过了!

#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define MAXTOKEN 100

enum { NAME, PARENS, BRACKETS };

void dcl(void);
void dirdcl(void);
int gettoken(void);
int tokentype;
char token[MAXTOKEN];
char name[MAXTOKEN];
char datatype[MAXTOKEN];
char out[1000];

main()
{
 while (gettoken() !=
'@') {
  strcpy(datatype, token);
 out[0] = '/0';
 dcl();
 if (tokentype != '/n')
  printf("syntax error/n");
 printf("%s: %s %s/n",name,out, datatype);
 }

return 0;
}
int gettoken(void)
{
 int c,getch(void);
 void ungetch(int);
 char *p = token;

 while ((c = getch()) == ' ' || c == '/t')
  ;
 if (c == '(')
 {
  if ((c = getch()) == ')')
  {
   strcpy(token,"()");
   return tokentype = PARENS;
  }
  else {
   ungetch(c);
   return tokentype = '(';
  }
 } else if (c == '['){
  for (*p++ = c; (*p++ = getch()) != ']'; )
       ;
  *p = '/0';
  ungetch(c);
  return tokentype = BRACKETS;
 } else if (isalpha(c)) {
  for (*p++ = c; isalnum(c = getch()); )
   *p++ = c;
  *p = '/0';
  ungetch(c);
  return tokentype = NAME;
 } else
  return tokentype = c;
}
#define BUFSIZE 100

char buf[BUFSIZE];
int bufp = 0;

int getch(void)
{
 return (bufp > 0) ? buf[--bufp] : getchar();
}

void ungetch(int c)
{
 if (bufp >= BUFSIZE)
  printf("ungetch: too many characters/n");
 else
  buf[bufp++] = c;
}


void dcl(void)
{
 int ns;

 for (ns = 0; gettoken() == '*'; )
  ns++;
 dirdcl();
 while (ns-- > 0)
  strcat(out, " pointer to");
}
void dirdcl(void)
{
 int type;

 if (tokentype == '(') {
  dcl();
  if (tokentype != ')')
   printf("error: missing ) /n");
 } else if (tokentype == NAME)
  strcpy(name, token);
 else
  printf("error: expected name or (dcl)/n");
 while ((type=gettoken()) == PARENS || type == BRACKETS)
  if (type == PARENS)
   strcat(out, " function returning");
  else {
   strcat(out, " array");
   strcat(out,token);
   strcat(out," of");
  }
}

 

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值