| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 9768 人关注过本帖
标题:VS2017中scanf_s过不去
只看楼主 加入收藏
see235959850
Rank: 2
等 级:论坛游民
帖 子:380
专家分:29
注 册:2016-12-21
结帖率:100%
收藏
 问题点数:0 回复次数:7 
VS2017中scanf_s过不去
程序代码:
#include<stdio.h>
int main()
{
    struct Student
    {
        int num;
        char name[20];
        float score;
    }student1,student2;
    printf("input student1:\n");
    scanf_s("%d%s%f", &student1.num, student1.name, &student1.score);
    printf("input student2:\n");
    scanf_s("%d%s%f", &student2.num, student2.name, &student2.score);
    printf("The higher score is:\n");
    if (student1.score > student2.score)
        printf("%d %s %6.2f", student1.num, student1.name, student1.score);
    else if(student1.score<student2.score)
        printf("%d %s %6.2f", student2.num, student2.name, student2.score);
    else
    {
        printf("%d %s %6.2f", student1.num, student1.name, student1.score);
        printf("%d %s %6.2f", student2.num, student2.name, student2.score);
    }
    return 0;
}

我照着答案敲的
2017-01-30 09:26
see235959850
Rank: 2
等 级:论坛游民
帖 子:380
专家分:29
注 册:2016-12-21
收藏
得分:0 
d:\程序\helloworld\helloworld\源.cpp(11): warning C4477: “scanf_s”: 格式字符串“%s”需要类型“unsigned int”的参数,但可变参数 3 拥有了类型“float *”
d:\程序\helloworld\helloworld\源.cpp(11): note: 此参数用作缓冲区大小
d:\程序\helloworld\helloworld\源.cpp(11): warning C4473: “scanf_s”: 没有为格式字符串传递足够的参数
d:\程序\helloworld\helloworld\源.cpp(11): note: 占位符和其参数预计 4 可变参数,但提供的却是 3 参数
d:\程序\helloworld\helloworld\源.cpp(11): note: 缺失的可变参数 4 为格式字符串“%f”所需
d:\程序\helloworld\helloworld\源.cpp(13): warning C4477: “scanf_s”: 格式字符串“%s”需要类型“unsigned int”的参数,但可变参数 3 拥有了类型“float *”
d:\程序\helloworld\helloworld\源.cpp(13): note: 此参数用作缓冲区大小
d:\程序\helloworld\helloworld\源.cpp(13): warning C4473: “scanf_s”: 没有为格式字符串传递足够的参数
d:\程序\helloworld\helloworld\源.cpp(13): note: 占位符和其参数预计 4 可变参数,但提供的却是 3 参数
d:\程序\helloworld\helloworld\源.cpp(13): note: 缺失的可变参数 4 为格式字符串“%f”所需
2017-01-30 09:27
see235959850
Rank: 2
等 级:论坛游民
帖 子:380
专家分:29
注 册:2016-12-21
收藏
得分:0 
解决了
2017-01-30 09:33
see235959850
Rank: 2
等 级:论坛游民
帖 子:380
专家分:29
注 册:2016-12-21
收藏
得分:0 
这个结构体输出和平时输出也没什么区别嘛,还麻烦
2017-01-30 09:40
see235959850
Rank: 2
等 级:论坛游民
帖 子:380
专家分:29
注 册:2016-12-21
收藏
得分:0 
如果是a1,a2的话,能简单点
2017-01-30 09:41
douxin
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-8-10
收藏
得分:0 
回复 3楼 see235959850
楼主怎么解决的?
2017-08-10 09:26
grmmylbs
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:54
帖 子:1409
专家分:5845
注 册:2016-2-14
收藏
得分:0 
scanf_s和scanf参数不一样
2017-08-10 10:08
wy2088511
Rank: 2
等 级:论坛游民
威 望:1
帖 子:12
专家分:53
注 册:2009-11-19
收藏
得分:0 
scanf_s("%d%s%f", &student1.num, student1.name,&student1.score);改成 scanf_s("%d%s%f", &student1.num, student1.name, 20,&student1.score);就好了,因为scanf_s为了防止输入越界,要传入一个长度
2017-08-10 11:56
快速回复:VS2017中scanf_s过不去
数据加载中...
 
   



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

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