Visual Studio Community 2015 - _CRT_SECURE_NO_WARNINGS
日期: 2020-03-21 分类: 跨站数据测试 353次阅读
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
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
注意,必须是文件的第一行,要在没有 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
除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog
上一篇: 没有品牌影响力,即使AI产品研发出来,能卖给谁呢?
下一篇: Java的发展简史
精华推荐