c Programming/C Reference/wchar.h/swprintf

From Wikibooks, open books for an open world
Jump to: navigation, search

swprintf is a C standard library function as defined in wchar.h and it's required header files are stdio.h and wchar.h. It has function signature as

'int swprintf(wchar_t *s,, size_t n, const wchar_t format,...);

n the signature of swprintf:
s : it is pointer to the buffer where you want to store the formatted string.The formatting string provides the extra arguments required
n : it is maximum number of characters to be stored in the buffer appending the null character.
format : this is the wide character string which shows the format of the output.

Usage[edit]

The swprintf function perform wide character output to an array of wide characters. The programmer must ensure that there is space for at least 'n' wide characters at 's'.


Description[edit]

swprintf() is the function which prints the output after the null character in the consecutive wide character starting at *s.And it prints no n more characters up to next null character appears.swprintf is wide character version of sprintf.pointer arguments to swprintf are wide character string

return value[edit]

This function returns number of character written or -1 if an error exist.If s(pointer to buffer) or format is a null pointer ,invalid parameter is invoked.If the program allows to run this code the it returns -1 or errno is set to EINVAL. swprintf returns number of wide character which are stored in 's'(buffer) not counting the last null character.

example[edit]