1

当我尝试编译我的代码时,我收到三个错误,全部说明“错误:输入末尾的预期声明或语句”都指向同一行。该行会根据我注释掉的部分而变化。在仍然出现错误的情况下,我可以留在函数中的最少代码是函数顶部的声明行。

所有其他解决方案都指向某处没有封闭括号,但我已经搜索过并且找不到。

任何帮助,将不胜感激。

void get_agents(struct Base* s) {
int count;
char c = 'A'; //temp char declartion
char temp1, temp2;
char *file, *extra, *line;

line = malloc(sizeof(char)*128); 
file = malloc(sizeof(char)*256); 
extra = malloc(sizeof(char)*256); 

s->agentfile = fopen(s->agentfilename, "r");
while (c != EOF) {
    fgets(line,500,s->agentfile);
    c = line[0]; //gets first char from line
    if (c != '#') {
        struct Agent* newAge = malloc(sizeof(struct Agent));
        struct Agent* agentNum = malloc(sizeof(struct Agent));

        newAge->next = 0; 
        sscanf(line, "%d %d %c %s%c%s%c", &newAge->posx, &newAge->posy,
        &newAge->name, file, &temp1, extra, &temp2);

        agentNum = s->start //sets agentNum to the first agent in list
        if (agentNum == NULL) { //does first agent exist?
            s->start = newAge; //first agent in list
        } else {
            while (agentNum->next) { //is this not the last agent?
                agentNum = agentNum->next; //get the next agent
            }
            agentNum->next = newAge; //else, set newagent to be new last
        }
    }
}
}
4

2 回答 2

4

;之前失踪if()

agentNum = s->start ;
                    ^
   if (agentNum == NULL) { //doe
于 2013-09-24T06:20:59.423 回答
2
   agentNum = s->start //sets agentNum to the first agent in list

;(分号)在语句的末尾。

;在语句末尾添加 (分号)

agentNum = s->start ; //sets agentNum to the first agent in list 
                    ^
于 2013-09-24T06:21:44.540 回答