0

Whats wrong i keep getting segfault

     for(int o = 0; o < n - 1; o++)
{
    if(candidates[o].votes > high0)
    {
        high0 = candidates[o].votes;
        name1 = candidates[o].name;
    }
     else if(candidates[p].votes == high0)
        {
        candidates[o].votes = high1;
        name2 = candidates[o].name;
        }

    }
   printf("%s\n", name1);
    printf("%s\n", name2);
1

Segfault is a memory error which is caused due to leakage in memory or aka bytes

I need to see the whole code

Remember you only need to print the name of the candidate(s) once it's vote matches the max number of votes in the election

So first use for-loop to iterate through every candidate to store the max number of votes in the election

Then

Use other for-loop to check and match the votes of the candidates with int max and printf the name

If I helped you be sure to tick the answer to keep other smiling too ;)

If you need any further assistance get back to me.

| improve this answer | |
  • I used your help and i got all :) Thank you so much! – iliketurtlz Jul 15 at 16:01
  • Hahaha no problem 😊 – Shahroz Ali Jul 15 at 16:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .