0
我正在編寫一個使用數組顯示最小值,最大值和平均值的程序。在我的函數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]);
}
}
這是一個很好的問題。你正試圖防止緩衝區溢出攻擊,對吧?這是一個很好的閱讀。 http://stackoverflow.com/questions/456303/how-to-validate-input-using-scanf –