gpt4 book ai didi

c - 使用数组进行错误检查

转载 作者:行者123 更新时间:2023-11-30 17:59:44 25 4
gpt4 key购买 nike

我正在编写一个程序,它使用数组来显示最小值、最大值和平均值。在我的函数 getNumbers 中,我允许用户输入要存储的值。一旦处理完毕,我如何进行错误检查,这样用户就不能超出数组大小。

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

最佳答案

也许你可以尝试用 if 来“冒泡”你的 getNumber 函数。只要检查一下你是否越界就可以了。

关于c - 使用数组进行错误检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11182861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com