c - C 中的 Visual Studio 错误,0xfefefefe 处未处理的异常

标签 c windows visual-studio-2012 c11 tr24731

我正在学习如何在 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 MSDNscanf_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/

相关文章:

c - CentOS 6.5上D访问C库

c - 由于 dll 调用导致奇怪的堆栈损坏

c++ - Windows,打开原始磁盘

python - Boost-Python C++ 项目构建,如何使用 Python 中的新库?

c++ - OpenCV:findHomography 生成一个空矩阵

c - 键入 C 时自动添加一个点 (.)

c - aio_write 比 ext4 上的普通写入需要更多时间?

ruby - 如何在 Windows 上的 Ruby 中获取文件创建时间?

python-3.x - time.perf_counter() 是否应该在 Windows 上的 Python 中跨进程保持一致?

c++ - VS2012 node.js 模块 : troubleshooting LNK2005/LNK1169 errors