Visual Studio Community 2015-_CRT_SECURE_NO_WARNINGS
Visual Studio Community 2015 _crt_secure_no_warnings
1. _CRT_SECURE_NO_WARNINGS
1>------ Build started: Project: yongqiang, Configuration: Debug Win32 ------ 1> foreverstrong.c 1>d:visual_studio_workspaceyongqiangyongqiangforeverstrong.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 kits10include10.0.10240.0ucrtstdio.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 #include 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 ('
' == input_string[strlen(input_string) - 1]) { input_string[strlen(input_string) - 1] = ' ' } word_length = compute_word_length(input_string) printf('%d
', word_length) return 0 }
ループを終了します。
qiang + Enter Ctrl + Z + Enter Ctrl + Z + Enter