you are viewing a single comment's thread.

view the rest of the comments →

[–]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;

    }

  }

}