Code blocks MinGW and the %n conversion character

后端 未结 2 1479
萌比男神i
萌比男神i 2021-01-13 06:35

I am trying to use a conversion character to count the number of chars printed so far with the following code.

#include 
int main(void) {
             


        
相关标签:
2条回答
  • 2021-01-13 07:12

    It looks like this is a Windows issue, this article says:

    The default C-RunTime Library (msvcrt.dll) on Vista seems to have %n disabled by default - security reasons of course

    It looks like there is a _set_printf_count_output to enable it.

    BLUEPIXY found that in order to get it working outside Visual Studio you need to define __USE_MINGW_ANSI_STDIO:

    #define __USE_MINGW_ANSI_STDIO 1
    
    0 讨论(0)
  • 2021-01-13 07:23

    use compile option -D__USE_MINGW_ANSI_STDIO

    E.g

    >gcc prog.c -D__USE_MINGW_ANSI_STDIO
    

    or

    >clang prog.c -D__USE_MINGW_ANSI_STDIO
    

    Another solution is placing this command above the first import statement like so (see below). This will ensure that the ANSI I/O standards are preferred over Microsoft's. More information in this link here.

    #define __USE_MINGW_ANSI_STDIO 1
    #include <stdio.h>
    
    0 讨论(0)
提交回复
热议问题