共用方式為


_set_printf_count_output

啟用或停用、 _printf_lwprintf_wprintf_l- -family 函式中printf %n 格式的支援。

語法

int _set_printf_count_output(
   int enable
);

參數

enable
啟用 %n 支援的非零值,0 表示停用 %n 支援。

屬性值或傳回值

在呼叫此函式之前,%n 支援的狀態:如果已啟用 %n 支援,則為非零,如果停用則為 0。

備註

由於安全性原因,預設printf會停用 %n 格式規範及其所有變體的支援。 如果在格式規格中printf遇到 %n,預設行為是叫用無效的參數處理程式,如參數驗證中所述。 使用非零自變數呼叫_set_printf_count_output會導致 printf-family 函式解譯 %n,如格式規格語法: printfwprintf 函式中所述

需求

常式 必要的標頭
_set_printf_count_output <stdio.h>

如需相容性詳細資訊,請參閱相容性

範例

// crt_set_printf_count_output.c
#include <stdio.h>

int main()
{
   int e;
   int i;
   e = _set_printf_count_output( 1 );
   printf( "%%n support was %sabled.\n",
        e ? "en" : "dis" );
   printf( "%%n support is now %sabled.\n",
        _get_printf_count_output() ? "en" : "dis" );
   printf( "12345%n6789\n", &i ); // %n format should set i to 5
   printf( "i = %d\n", i );
}
%n support was disabled.
%n support is now enabled.
123456789
i = 5

另請參閱

_get_printf_count_output