Visual Studio Community 2015 - _CRT_SECURE_NO_WARNINGS
程序员文章站
2022-03-22 14:44:22
...
Visual Studio Community 2015 - _CRT_SECURE_NO_WARNINGS
_CRT_SECURE_NO_WARNINGS
1. _CRT_SECURE_NO_WARNINGS
1>------ Build started: Project: yongqiang, Configuration: Debug Win32 ------
1> foreverstrong.c
1>d:\visual_studio_workspace\yongqiang\yongqiang\foreverstrong.c(51): error 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.
1> c:\program files (x86)\windows kits\10\include\10.0.10240.0\ucrt\stdio.h(1270): note: see declaration of 'scanf'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
error 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.
error C4996: 'strtok': This function or variable may be unsafe. Consider using strtok_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
2. _CRT_SECURE_NO_WARNINGS
2.1 文件开头添加代码
#define _CRT_SECURE_NO_WARNINGS
注意,必须是文件的第一行,要在没有 include
任何头文件之前。
2.2 项目添加预处理定义
项目 -> 属性 -> 配置属性 -> C/C++ -> 预处理器 -> 预处理定义
_CRT_SECURE_NO_WARNINGS
a. 与前面的要用分号分开,后面加分号。
b. 换行添加。
/*
============================================================================
Name : hello_world.c
Author : Yongqiang Cheng
Version : Version 1.0.0
Copyright : Copyright (c) 2019 Yongqiang Cheng
Description : Hello World in C, Ansi-style
============================================================================
*/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
int compute_word_length(const char *input_string)
{
const char *string_pointer = input_string;
int string_length = 0;
int idx = 0;
int word_length = 0;
if (NULL == input_string)
{
return 0;
}
string_length = strlen(input_string);
if (0 == string_length)
{
return 0;
}
for (idx = string_length - 1; string_pointer[idx] != ' '; idx--)
{
word_length++;
if (string_length == word_length)
{
break;
}
}
return word_length;
}
int main()
{
char input_string[5000] = { 0 };
int word_length = 0;
int idx = 0;
while (EOF != scanf("%c", &(input_string[idx])))
{
idx++;
}
if ('\n' == input_string[strlen(input_string) - 1])
{
input_string[strlen(input_string) - 1] = '\0';
}
word_length = compute_word_length(input_string);
printf("%d\n", word_length);
return 0;
}
退出循环:
qiang + Enter
Ctrl + Z + Enter
Ctrl + Z + Enter
推荐阅读
-
win10开发必备:Visual Studio 2015 Update 1正式版下载汇总
-
visual studio 2015离线版msdn下载和安装图文教程
-
visual studio 2015 PreView环境搭建图文教程
-
Visual Studio 2015和 .NET Core安装教程
-
微软宣布:Visual Studio 2015与.NET 2015预览版已开放下载
-
Visual Studio 2015 安装图文详细步骤
-
如何安装visual studio 2015?visual studio 2015图文安装教程
-
Win7安装Visual Studio 2015失败的解决方法
-
Visual Studio 2015怎么改变WPF窗体程序的背景图片?
-
Visual Studio2015怎么安装Visual Assist X插件?