353500315 发表于 2020-11-5 14:21:18

请问这段代码有什么问题??

#include<stdio.h>
int main(void)
{
        float weight;
        float value;

        printf("Are you worth your weight in platinum? \n");
        printf("Let`s check it out. \n");
        printf("Please enter your weight in pounds:");

        scanf("%f", &weight);

        value = 1700.0*weight * 14.5833;
        printf("Your weight in platinum is worth $%.2f.\n", value);
        printf("You are easily worth that!If platinum prices drop,\n");
        printf("eat more to main tain your value.\n");

        return 0;
}




这个是编译器给出的错误解释:
                                          错误        C4996        'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.       

sunrise085 发表于 2020-11-5 14:33:13

本帖最后由 sunrise085 于 2020-11-5 14:35 编辑

新版的编译器中认为scanf不安全,让使用scanf_s替换。你把scanf换乘scanf_s试试
或者在文件开头加一句:
#define _CRT_SECURE_NO_WARNINGS

风过无痕1989 发表于 2020-11-5 14:34:29

我这里运行没有问题。出现这个警告是编译器引起的

解决方法如下:

      一:将原来的旧函数替换成新的安全函数,比如scanf_s函数

   二:更改预处理定义:

      项目->属性->配置属性->C/C++ -> 预处理器 -> 预处理器定义,增加:_CRT_SECURE_NO_DEPRECATE

   三:在预编译头文件 stdafx.h 里(要在没有include任何头文件之前)定义下面的宏:


             #define _CRT_SECURE_NO_DEPRECATE

                   #define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1

(方法来源于网络,没有亲自试验)

乐乐学编程 发表于 2020-11-5 23:57:42

还没解决吗?

LuLD 发表于 2020-11-6 08:27:45

楼上几位说的方法是可以的,我说一下另外一种,在项目属性里改下SDL检查设置
页: [1]
查看完整版本: 请问这段代码有什么问题??