Here is a very simple code that I'm trying to run:

#include <stdio.h>

void main()
{
    int x;
    printf( "TEST%n", &x );
}

I expect x to become equal 4 instead I'm getting fatal error.

I use Visual Studio 2008 and Windows XP.

During execution I get window saying "Microsoft Visual Studio C Runtime Library has detected a fatal error..."
Then debugger opens up dbghook.c file with _CRT_DEBUGGER_HOOK function.

Please help me understand what am I doing wrong?

有帮助吗?

解决方案

From the MSDN format type page:

Security Note The %n format is inherently insecure and is disabled by default; if %n is encountered in a format string, the invalid parameter handler is invoked as described in Parameter Validation. To enable %n support, see _set_printf_count_output.

其他提示

#include <stdio.h>

void main()
{
    int x;
    printf("%d\n",x);
}

You are using incorrect syntex for printf.Other thing is "&" is used for scanf.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top