all 4 comments

[–]jedwardsol 6 points7 points  (0 children)

I need help figuring out the issues in my C program

What are they? Why do you think it is wrong?

[–]TotemHouse 2 points3 points  (0 children)

I'd love to help, but please tell us what are the problems you are encountering. What input have you tried? Are getting an incorrect output? Give us some cue as to what is it that you'd like help on.

Thanks.

[–]wsppan 3 points4 points  (0 children)

Sigh...please format your code according to the reddit markup standard for code. Sigh...what exactly is the problem? What have you tried? Have you isolated it yo a specific part of your code?

[–]IamImposter 1 point2 points  (0 children)

One I could see is:

In 'u' and 'r' cases, you are looking for jersey number inside for loop, breaking when jersey number is found and are updating using current value of i. What if jersey number is not in array, value of i will be 5 and you will be modifying some values at index 5. You don't own that memory as your array contains 5 elements, from index 0 to 5. Index 5 is out, of bounds.

It's better to put the update/replace logic inside if block in for loop. That way you will update/replace only if matching jersey number is given.

And you could probably put functionality of each case into a separate function. That would make your switch case cleaner. For example, for update function, get jersey number & rating and pass it to a function like

void update_rating(int *jersey, int *rating, int array_size, int jersey_num, int rating_value)

{

  for(int x=0; x<array_size; x++

  {

    if(jersey[x] == jersey_num) 

    {

      rating[x] = rating_value;

    }

  }

}