# PSET3-Plurality. Check50 doesn't re

After finishing plurality, it fails check50. It returns "print_winner function did not print winner of election".

In print_winner function I did the following

void print_winner(void)

{

``````//create a pivot for bubble sorting

candidate temp;

//bubble sorting from bigger to smaller, winner is first on the list

for (int a=0; a < candidate_count - 1; a++)

{

for (int b=0; b < candidate_count - a - 1; b++)

{

if (candidates[b].votes < candidates[b+1].votes)

{

temp.name = candidates[b].name;

temp.votes = candidates[b].votes;

candidates[b].name = candidates[b+1].name;

candidates[b].votes = candidates[b+1].votes;

candidates[b+1].name = temp.name;

candidates[b+1].votes = temp.votes;

}

}

}

int total=1;

//compares the top of the list with the rest of the the values to search for a tie.

for (int c=1; c < candidate_count; c++)

{

if (candidates.votes == candidates[c].votes)

{

total++;

}

}

//create an array with the final number of the winners

string winners[total];

//migrate the winners to the variable winners

for (int i=0; i<total; i++)

{

winners[i]=candidates[i].name;

}

//print the winners

for (int i=0; i<total; i++)

{

printf ("%s \n", winners[i]);

}

return;
``````

It works when I check it manually, but somehow check50 doesn't recognize it. Any idea where I went wrong?

## 1 Answer

If you know you're printing the right answer, then it must be your formatting when you print. Try removing the space when you print each name. Use this `printf ("%s\n", winners[i]);` instead of `printf ("%s \n", winners[i]);`

• It worked! Thank you very much, that little space was making a lot of trouble. – oscar soberanes Mar 30 '20 at 16:47