今天在写一个简单的C程序时,需要用scanf函数获得一个字符串输入
char str[20];
scanf("%s", str);
但是编译程序时出现了如下警告”warning C4996: 'scanf': This function or variablemay be unsafe. Consider using scanf_s instead. To disabledeprecation, use _CRT_SECURE_NO_WARNINGS. See online help fordetails.
1>
这是因为scanf的声明在VS2005以后的版本中被认为是不安全的,需要使用scanf_S来代替。只要在程序中添加#define_CRT_SECURE_NO_DEPRECATE 或者 scanf函数修改为scanf_s即可。