如何修复 Visual Studio 中的堆栈溢出错误?

问题描述

当我尝试在 Visual Studio 2019 中调试下面列出的代码时,我在 main 函数的系统暂停行之前收到堆栈 cookie 缓冲区溢出错误。我不知道如何解决它。我是编程新手,不知道该怎么做。有人可以帮我理解吗?

#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]);
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)