Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

#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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top