我最近系统地开始了c语言的学习。 在VS2019中使用scanf_s为一系列字符串赋值时发生错误。 错误如下。0x7837EF8C (ucrtbased.dll)处(位于 Project2.exe 中)引发的异常: 0xC0000005: 写入位置 0x01342000 时发生访问冲突。
**
研究了一些资料后,我们发现该问题应该是因为VS2019编译器建议使用scanf_s函数来防止原始scanf函数的数组越界问题。 (在vs2019中使用scanf函数时,将报告编译失败。 )
# define word _ size 26 charname [ word _ size ]; scanf_s('%s ',name ); 这样会报告错误。
通过指定数组名称和数组长度即可进行编译。
# define word _ size 26 charname [ word _ size ]; scanf_s('%s ',name,WORD_SIZE );