Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Library Function - wctomb()

C Library Function - wctomb()

C Standard Library - <stdlib.h> C Standard Library -

Description

C library function *int wctomb(char str, wchar_t wchar) Converts the wide character wchar into its multibyte representation and stores it at the start of the str character array.

Declaration

Below is the declaration of the wctomb() function.



int wctomb(char *str, wchar_t wchar)

Parameters

Return Value

Example

The following example demonstrates the use of the wctomb() function.



#include 

#include 



int main()

{

   int i;

   wchar_t wc = L'a';

   char *pmbnull = NULL;

   char *pmb = (char *)malloc(sizeof( char ));



   printf("要转换的宽字符:\n");

   i = wctomb( pmb, wc );

   printf("被转换的字符:%u\n", i);

   printf("多字节字符:%.1s\n", pmb);



   printf("当要转换的字符为 NULL 时尝试转换:\n");

   i = wctomb( pmbnull, wc );

   printf("被转换的字符:%u\n", i);

   /* Does not output any value */

   printf("多字节字符:%.1s\n", pmbnull);

   

   return(0);

}

Let's compile and run the above program, which will produce the following result:



Wide characters to be converted:

被转换的字符:1

多字节字符:a

Attempt conversion when the character to be converted is NULL:

被转换的字符:0

Multibyte characters:

C Standard Library - <stdlib.h> C Standard Library -