帮忙看下哪里的parse error

t871215x 2011-02-12 10:59:01
编译器是: JFE AND GCC

代码:


#include <stdio.h>

#define STACKSIZE 100
#define PATHSIZE 30
#define TABSIZE 4

#define OK 0
#define ERROR 1

#define RETURN(stat)\
{\
getchar();\
return(stat);\
}

struct stack
{
int top;
int array[STACKSIZE];
};
typedef struct stack STACK;

STACK bracket,row,col;
bracket.top = 0;//parse error before `.' ????????????
row.top = 0;//parse error before `.' ????????????
col.top = 0;//parse error before `.' ????????????

void push(STACK stack,int data)
{
if(STACKSIZE == stack.top)
{
printf("The stack is full!\n");
return;
}
stack.array[stack.top++] = data;
}

int pop(STACK stack)
{
if(0 == (stack.top--))
{
printf("The stack is empty!\n");
RETURN(ERROR);
}
return(stack.array[stack.top]);
}

char get_file(char *dest)
{
unsigned int i = 0;

printf("First,input the path of the file you want to open:\n");
if(NULL == fgets(dest,PATHSIZE,stdin))
{
printf("fgets error!\n");
RETURN(ERROR);
}
while('\n' != *(dest + (i++)));
*(dest + i) = '\0';
RETURN(OK);
}

void check_stack(void)
{
int data;
int numCol = 0,numRow = 0;

while(ERROR != (data = pop(bracket)))
{
numCol = pop(col);
numRow = pop(row);
printf("row [%3d] col [%3d] : { not matched!\n\n",numRow,numCol);
}
}

int main(void)
{
char file[PATHSIZE];
char ch = '\0';
unsigned int numRow = 0,numCol = 0;
FILE *fp;

if(ERROR == get_file(file))
{
printf("get_file error!\n");
RETURN(ERROR);
}
if(NULL == (fp = fopen(file,"r")))
{
printf("fopen error: %s!\n",file);
RETURN(ERROR);
}
while(EOF != (ch = fgetc(fp)))
{
if('{' == ch)
{
push(bracket,'{');
push(col,numCol);
push(row,numRow);
}
else if('}' == ch)
{
pop(bracket);
pop(col);
pop(row);
}
else if('\n' == ch)
{
numCol = 0;
numRow++;
}
else if('\t' == ch)
{
numCol += TABSIZE;
continue;
}
numCol++;
}
fclose(fp);
check_stack();
RETURN(OK);
}

...全文
212 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
arong1234 2011-02-12
  • 打赏
  • 举报
回复
无论数组还是指针,dest[i++]都行啊?为什么要区别数组还是指针?[Quote=引用 4 楼 t871215x 的回复:]
完整的错误提示:
C:\DOCUME~1\ADMINI~1\桌面\task\PROGRA~3.C:24: parse error before `.'

不用dest[i++]是因为在被调函数中,无法得知参数dest在调用函数中是定义为数组或是指针

错误已找出,谢谢2楼!分稍后送出!
[/Quote]
justkk 2011-02-12
  • 打赏
  • 举报
回复
指针也可以用数组的方式来使用
在函数调用时,即使传入一个数组,也退化为指针
t871215x 2011-02-12
  • 打赏
  • 举报
回复
完整的错误提示:
C:\DOCUME~1\ADMINI~1\桌面\task\PROGRA~3.C:24: parse error before `.'

不用dest[i++]是因为在被调函数中,无法得知参数dest在调用函数中是定义为数组或是指针

错误已找出,谢谢2楼!分稍后送出!
arong1234 2011-02-12
  • 打赏
  • 举报
回复
*(dest + (i++)));
这种表达式明显让自己代码难看清楚,为什么不用dest[i++]?
justkk 2011-02-12
  • 打赏
  • 举报
回复
bracket.top = 0;
row.top = 0;
col.top = 0;
这3行是赋值语句,应该放在函数体内

或者初始化的方式赋值
STACK bracket = {0};
arong1234 2011-02-12
  • 打赏
  • 举报
回复
出现错误时编译器会告诉你哪行出错的,所以不要把关键字摆出来问,而应该贴完整错误信息

70,037

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧