在编写如下代码时发生了C26052错误
#include<stdio.h>
#include<math.h>
int main()
{
int n;
double a[100] = {0};
while (~scanf_s("%d",&n)&&n>2&&n<=100)
{
double sum = 0;
for (int i = 0; i < n; i++)
{
scanf_s("%lf", &a[i]);
}
double max = a[0], min = a[0];
int maxnum = 0, minnum = 0;
for (int i = 1; i < n; i++)
{
if (max<a[i])
{
max = a[i];
maxnum = i;
}
if (min>a[i])
{
min = a[i];
minnum = i;
}
}
a[maxnum] = 0;
a[minnum] = 0;
for (int i = 0; i < n; i++)
{
sum += a[i];
}
printf("%.2lf\n", sum / (n - 2));
}
return 0;
}
出在scanf_s的地方
C26052错误描述如下
C26052: Potentially unconstrained access using expression '(double *)(&a[i)"Buffer a is passed to function scanf_s as unannotated parameter 2
None of the other parameters seem to be constrained by the buffer length
Buffer accessed is a
Buffer is of length 100 elements (8 bytes/element)[size of variable]
Values of variables:
a[0] = a[0]`12
i = {loop iterations}'10
while (~scanf_s("%d",&n)&&n>2&&n<=100)
这个语句改成几条语句
while(1){
里面读取再判断
}
定位一下错误行是哪一行
C和C++完整教程:https://blog.csdn.net/it_xiangqiang/category_10581430.html
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632
非常感谢您使用有问必答服务,为了后续更快速的帮您解决问题,现诚邀您参与有问必答体验反馈。您的建议将会运用到我们的产品优化中,希望能得到您的支持与协助!
速戳参与调研>>>https://t.csdnimg.cn/Kf0y