This keeps coming up with "segmentation fault" when I run it although everything I want it do is working. It seems to be coming from the last if statement because there's no fault when I delete that bracket but I can't figure out what's wrong with the bracket/an alternative to the bracket.
int a = candidate_count;
string winner[a];
for (int i = 0; i < candidate_count; i++)
{
for (int j = i + 1; j < candidate_count; j++)
{
if (candidates[i].votes > candidates[j].votes)
{
winner[i] = candidates[i].name;
}
if ((candidates[i].votes == candidates[j].votes) && (winner[i] = candidates[i].name))
{
winner[j] = candidates[j].name;
}
}
}
for (int i = 0; i < a; i++)
{
if (strcmp(winner[i], candidates[i].name) == 0)
{
printf("%s\n", winner[i]);
}
}
return;
}
Please help, thanks!