0

我想创建一个结构数组:

typedef struct
{
   int id;
   int department;
}employee;

int main(int argc, char *argv[])
{
 int i;
 employee job[3];   ////////////////error
 for (i=0;i<3;i++)
 {
    //do something
 }  
return 0;
}

问题是当我想编译时出现以下错误:

';' 之前的语法错误 标记并指向我标记的行

有什么帮助吗?

谢谢

4

1 回答 1

2

根据以下记录,该代码独立存在,很好:

pax> cat qq.c
typedef struct {
   int id;
   int department;
} employee;

int main (int argc, char *argv[]) {
    int i;
    employee job[3];   ////////////////error
    for (i=0;i<3;i++) {
        //do something
    }  
   return 0;
}
pax> gcc -o qq qq.c
pax> 

. 您可能需要检查的一些事项是:

  • 有什么#define类似employeeor的东西job吗?
  • 你确定employee这两个地方的拼写一样吗?
  • 你确定你拥有所有你声称拥有的分号吗?
  • 您的代码中是否有任何“有趣”的字符(那些看起来不可见但仍将您的输入流填充到编译器的字符)?

A good first start would be to comment out the errant line and see if you get the error on the following line. That should narrow it down to either that line (no error) or a previous line (still have error).

You can see the entire file in hex mode (looking for funny characters) if you do something like:

od -xcb myfile.c

(under Linux - Windows I'm not sure though, if you have gvim, you can convert it to hex with a menu item).

于 2012-12-05T00:47:55.370 回答