0

I'm writing a program that's using arrays to display a minimum value, a maximum value, and the average. In my function getNumbers, I'm allowing the user to enter values to store. How can I error check once it's been processed that way the user can't go beyond the array size.

int getNumbers(int array[ARRAY_SIZE], int minimumValue, int maximumValue, sumValue, avgValue)
{
    int i;
    printf("Enter integers to store inside the array :");
    for(i = 0; i<= ARRAY_SIZE-1; i++)
    {
        scanf("%d", &array[i]);
    }
 }
theGrayFox
  • 921
  • 1
  • 10
  • 22
  • 2
    That's an excellent question. You're trying to prevent a buffer overflow attack, right? Here is a good read. http://stackoverflow.com/questions/456303/how-to-validate-input-using-scanf – mj_ Jun 25 '12 at 02:46

1 Answers1

0

Maybe you could try "bubbling" your getNumber function with an if. Just make that if check if you're going off bounds.

OFRBG
  • 1,653
  • 14
  • 28