我正在学习如何在 Visual Studio 中编写 C,这是我的代码,
#include<stdio.h>
int main() {
char me[20];
printf("What is your name?");
scanf_s("%s", me);
printf("darn glad to meet you, %s!\n", me);
return(0);
}
现在,输入所有内容后,我会弹出错误“Project14.exe 中 0xFEFEFEFE 处未处理的异常:0xC00001A5:已检测到无效的异常处理程序例程(参数:0x00000003)”
最佳答案
您使用了 scanf_s()
错误。方式described in MSDN是 scanf_s("%s", me, sizeof me);
此外,您确实应该检查函数的返回值
if (scanf_s("%s", me, (unsigned)sizeof me) != 1) /* error */;
另请注意 MSDN 描述和 C11 Standard description除了 MSDN 没有告知您该函数对于符合标准的实现是可选的之外,只有细微的差别。如果您打算在 Windows 以外的环境中运行代码,您可能需要添加对函数是否存在的检查或使用其他方式获取用户输入。
#ifdef __STDC_LIB_EXT1__
// use Annex K functions at will
#else
// do not use Annex K functions
#endif
关于c - C 中的 Visual Studio 错误,0xfefefefe 处未处理的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30683639/