When I attempt to debug the code listed below in Visual Studio 2019, I get a stacked cookie buffer overrun error before the system pause line of the main function. I can not figure out how to fix it. I am new to programming and have no clue what to do. Can someone please help me understand?
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
/************************************************************************************/
int Greater(int na, int nb);
void DisplayArray(int arr[], int asize);
/************************************************************************************/
/************************************************************************************/
int main(void)
{
int myArray[10] = { 43, 24, 76, 11, 37, 34, 55, 49, 5 }; /* initialize an array */
int asize = 10; /* set the size of the above array */
int na, nb;
int result;
printf("Enter 2 integers\n");
scanf("%d %d", &na, &nb);/* the variables were missing the & in the scanf function call*/
result = Greater(na, nb);
fprintf(stdout, "na = %d nb = %d greater = %d\n", na, nb, result);
ModifyArray(myArray, asize);
fprintf(stdout, "Array after modification\n");
DisplayArray(myArray, asize);
system("pause");
return 0;
}
/***************************************************************************************
This function returns the larger of its two arguments
***************************************************************************************/
int Greater(int na, int nb) {
if (na >= nb)
return na;
else
return nb;
}
/***************************************************************************************
This function modifies the elements of an array
***************************************************************************************/
int ModifyArray(int arr[], int asize) {
int i;
/* Add 5 to each element of array */
for (i = 0; i <= asize; i++); {
arr[i] += 5;
}
}
/***************************************************************************************
Display function
/***************************************************************************************/
void DisplayArray(int arr[], int asize) {
int i;
for (i = 0; i < asize; i++) {
fprintf(stdout, "i = %d arr[i] = %d\n", i, arr[i]);
}