nikora
nikora

Reputation: 817

Strcmp crashes application

I have this function

int does_exist_in_array(char team[], struct team *teams) {
    int i;
    for(i = 0; i < MAX_TEAMS_AMOUNT; i++) {
        if(!strcmp(team, teams[i].name)) {
            return 1;
        }
    }
    return 0;
}

It crashes when i run the application. Anyone know what is wrong? Do i use it wrong?

Upvotes: 0

Views: 5992

Answers (1)

cnicutar
cnicutar

Reputation: 182639

This can happen for a number of reasons:

  • Either argument is NULL or otherwise an invalid pointer
  • The string pointed by either argument is not 0-terminated
  • There are fewer than MAX_TEAMS_AMOUNT team elements

Upvotes: 5

Related Questions