当我尝试编译我的代码时,我得到了三个错误 “错误:输入结束时的预期声明或声明” 所有人都指向同一条线。该行根据我已注释掉的部分而变化。我仍然可以在函数中保留最少量的代码,同时仍然得到错误的是函数顶部的声明行。
所有其他解决方案都指向某处没有封闭的括号,但我搜索过但找不到一个。
任何帮助将不胜感激。
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
}
}
}
}
答案 0 :(得分:4)
在;
之前遗失if()
:
agentNum = s->start ;
^
if (agentNum == NULL) { //doe
答案 1 :(得分:2)
agentNum = s->start //sets agentNum to the first agent in list
声明末尾没有;
(分号)。
在声明
的末尾添加;
(分号)
agentNum = s->start ; //sets agentNum to the first agent in list
^