sparcloud32
sparcloud32

Reputation: 21

C compile error: expected declaration or statement at end of input

When I try to compile my code I get three errors all stating "error: expected declaration or statement at end of input" All pointing to the same line. The line changes depending on sections that I have commented out. The least amount of code I can leave still in the function while still getting the error is the declaration lines at the top of the function.

All other solutions point to there not being a closed bracket somewhere, but I have searched and cannot find one.

Any help would be appreciated.

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
        }
    }
}
}

Upvotes: 1

Views: 31311

Answers (2)

cerkiewny
cerkiewny

Reputation: 2851

   agentNum = s->start //sets agentNum to the first agent in list

No ; (semicolon) at the end of statement.

Add ; (semicolon) at the end of statement

agentNum = s->start ; //sets agentNum to the first agent in list 
                    ^

Upvotes: 2

Grijesh Chauhan
Grijesh Chauhan

Reputation: 58271

missing ; before if():

agentNum = s->start ;
                    ^
   if (agentNum == NULL) { //doe

Upvotes: 4

Related Questions