| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4642 人关注过本帖
标题:一个报错的修改 warning: ignoring return value of ‘scanf’, declared w ...
只看楼主 加入收藏
温柔
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2019-10-28
结帖率:60%
收藏
 问题点数:0 回复次数:2 
一个报错的修改 warning: ignoring return value of ‘scanf’, declared with attribute warn_
#include <stdio.h>

int main ()
{
    struct student
    {
        char name[10];
        char no[10];
        float score;
    };
    int n;
    int i;
    scanf("%d",&n);
    struct student stu[n];
    struct student max;
    struct student min;
    for (i=0;i<n;i++)
    {
    scanf("%s %s %f ",stu[i].name,stu[i].no,&stu[i].score);
    }
    max=stu[0];
    min=stu[0];
    for(i=0;i<n;i++)
    {
   
        if (max.score<stu[i].score)
            max = stu[i];
        if (min.score>stu[i].score)
            min=stu[i];
    }
    printf("%s %s\n",max.name,max.no);
    printf("%s %s\n",min.name,min.no);
    return 0;
}
a.c:13:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ^~~~~~~~~~~~~~
a.c:19:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s %s %f ",stu[i].name,stu[i].no,&stu[i].score);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
搜索更多相关主题的帖子: score scanf min stu max 
2019-11-12 21:52
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:0 
如果是OJ等,scanf一定成功,不需要判断其返回值。
咦,我才回过神来,你想问什么?
2019-11-13 09:30
纯蓝之刃
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:76
帖 子:565
专家分:3690
注 册:2019-7-29
收藏
得分:0 
你这个应该只是告警吧,scanf是由返回值的,你的编译器的 [-Wunused-result]检查规则检查了返回值项目,你没有使用scanf的返回值,所以告警了。scanf会返回输入的参数的个数。所以你可以这样写
if((flag=scanf("%s %s %f ",stu[i].name,stu[i].no,&stu[i].score))==3)

一沙一世界,一花一天堂。无限掌中置,刹那成永恒。
2019-11-13 20:03
快速回复:一个报错的修改 warning: ignoring return value of ‘scanf’, decla ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013771 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved