wprintf(3) Library Functions Manual wprintf(3)

wprintf, fwprintf, swprintf, vwprintf, vfwprintf, vswprintf - conversão de saída formatada de caracteres largos

Biblioteca C Padrão (libc, -lc)

#include <stdio.h>
#include <wchar.h>
int wprintf(const wchar_t *restrict format, ...);
int fwprintf(FILE *restrict stream,
             const wchar_t *restrict format, ...);
int swprintf(wchar_t wcs[restrict .maxlen], size_t maxlen,
             const wchar_t *restrict format, ...);
int vwprintf(const wchar_t *restrict format, va_list args);
int vfwprintf(FILE *restrict stream,
             const wchar_t *restrict format, va_list args);
int vswprintf(wchar_t wcs[restrict .maxlen], size_t maxlen,
             const wchar_t *restrict format, va_list args);
Requisitos de macro de teste de recursos para o glibc (consulte feature_test_macros(7)):

Todas as funções mostradas acima:

    _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE
        || _POSIX_C_SOURCE >= 200112L

A família de funções wprintf() é a equivalente para caracteres largos à família de funções printf(3). Ela realiza a saída formatada de caracteres largos.

As funções wprintf() e vwprintf() realizam saída de caracteres largos para stdout. stdout não deve ser orientado a byte; veja fwide(3) para maiores informações.

As funções fwprintf() e vfwprintf() realizam saída de caracteres largos para fluxo. fluxo não deve ser orientado a byte; veja fwide(3) para maiores informações.

As funções swprintf() e vswprintf() realizam saída de caracteres largos para um array de caracteres largos. O programador deve garantir que há espaço suficiente para no mínimo maxlen caracteres largos em wcs.

Estas funções são como as funções printf(3), vprintf(3), fprintf(3), vfprintf(3), sprintf(3), vsprintf(3) exceto pelas seguintes diferenças:

A formato é uma string de caracteres largos.
A saída consiste de caracteres largos, não bytes.
swprintf() e vswprintf() recebem um argumento maxcomp, sprintf(3) e vsprintf(3) não recebem. (snprintf(3) e vsnprintf(3) recebem um argumento maxcomp, mas estas funções não retornam -1 quando ocorre um estouro de buffer no GNU/Linux.)

O tratamento de caracteres de conversão c e s é diferente:

Se nenhum modificador l está presente, o argumento int é convertido para um caractere largo por uma chamada a para a função btowc(3), e o caractere largo resultante é escrito. Se um modificador l está presente, o argumento wint_t (caractere largo) é escrito.
If no l modifier is present: the const char * argument is expected to be a pointer to an array of character type (pointer to a string) containing a multibyte character sequence beginning in the initial shift state. Characters from the array are converted to wide characters (each by a call to the mbrtowc(3) function with a conversion state starting in the initial state before the first byte). The resulting wide characters are written up to (but not including) the terminating null wide character (L'\0'). If a precision is specified, no more wide characters than the number specified are written. Note that the precision determines the number of wide characters written, not the number of bytes or screen positions. The array must contain a terminating null byte ('\0'), unless a precision is given and it is so small that the number of converted wide characters reaches it before the end of the array is reached. If an l modifier is present: the const wchar_t * argument is expected to be a pointer to an array of wide characters. Wide characters from the array are written up to (but not including) a terminating null wide character. If a precision is specified, no more than the number specified are written. The array must contain a terminating null wide character, unless a precision is given and it is smaller than or equal to the number of wide characters in the array.

As funções retornam o número de caracteres largos escritos, excluindo-se o caractere largo nulo de terminação no caso das funções swprintf() e vswprintf(). Elas retornam -1 quando ocorre um erro.

Para uma explicação dos termos usados nesta seção, consulte attributes(7).

Interface Atributo Valor
wprintf(), fwprintf(), swprintf(), vwprintf(), vfwprintf(), vswprintf() Thread safety MT-Safe locale

C11, POSIX.1-2008.

POSIX.1-2001, C99.

O comportamento de wprintf() etc. depende da categoria LC_CTYPE da localização atual.

If the format string contains non-ASCII wide characters, the program will work correctly only if the LC_CTYPE category of the current locale at run time is the same as the LC_CTYPE category of the current locale at compile time. This is because the wchar_t representation is platform- and locale-dependent. (The glibc represents wide characters using their Unicode (ISO/IEC 10646) code point, but other platforms don't do this. Also, the use of C99 universal character names of the form \unnnn does not solve this problem.) Therefore, in internationalized programs, the format string should consist of ASCII wide characters only, or should be constructed at run time in an internationalized way (e.g., using gettext(3) or iconv(3), followed by mbstowcs(3)).

fprintf(3), fputwc(3), fwide(3), printf(3), snprintf(3)

A tradução para português brasileiro desta página man foi criada por Felipe M Pereira <Felipe.Pereira@ic.unicamp.br>, Ricardo C.O.Freitas <english.quest@best-service.com> e Rafael Fontenelle <rafaelff@gnome.org>.

Esta tradução é uma documentação livre; leia a Licença Pública Geral GNU Versão 3 ou posterior para as condições de direitos autorais. Nenhuma responsabilidade é aceita.

Se você encontrar algum erro na tradução desta página de manual, envie um e-mail para a lista de discussão de tradutores.

31 outubro 2023 Linux man-pages 6.06