Reputation: 1329
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?
Upvotes: 2
Views: 602
Reputation: 79
#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.
Upvotes: -3
Reputation: 409166
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
.
Upvotes: 4