# c32rtomb() function in C/C++

The c32rtomb() is a built-in function in C/C++ which converts 32 bit character representation to a narrow multibyte character representation. It is defined within the uchar.h header file of C++.

Syntax:

`size_t c32rtomb(char* s, char32_t c32, mbstate_t* p)`

Parameters: The function accepts three mandatory parameters as shown below:

• s: specifies the string where the multibyte character is to be stored.
• c16: specifies the 32 bit character to convert.
• p: specifies the pointer to an mbstate_t object used when interpreting the multibyte string.

Return Value: The function returns two values as shown below:

• On success of the program, the function returns the number of bytes written to the character array pointed to by s.
• If failed, then -1 is returned and EILSEQ is stored in err no.

Program 1:

 `// C++ program to illustrate the ` `// c32rtomb () function on it's success ` `#include ` `#include ` `#include ` `using` `namespace` `std; ` ` `  `int` `main() ` `{ ` `    ``const` `char32_t str[] = U``"GeeksforGeeks"``; ` `    ``char` `s; ` `    ``mbstate_t` `p{}; ` `    ``size_t` `length; ` `    ``int` `j = 0; ` ` `  `    ``while` `(str[j]) { ` `        ``// initializing the function ` `        ``length = c32rtomb(s, str[j], &p); ` `        ``if` `((length == 0) || (length > 50)) ` `            ``break``; ` ` `  `        ``for` `(``int` `i = 0; i < length; ++i) ` `            ``cout << s[i]; ` `        ``++j; ` `    ``} ` ` `  `    ``return` `0; ` `} `

Output:

```GeeksforGeeks
```

Program 2:

 `// C++ program to illustrate the ` `// c32rtomb () function on it's failure ` `#include ` `#include ` `#include ` `using` `namespace` `std; ` ` `  `int` `main() ` `{ ` `    ``const` `char32_t str[] = U``""``; ` `    ``char` `s; ` `    ``mbstate_t` `p{}; ` `    ``size_t` `length; ` `    ``int` `j = 0; ` ` `  `    ``while` `(str[j]) { ` `        ``// initializing the function ` `        ``length = c32rtomb(s, str[j], &p); ` `        ``if` `((length == 0) || (length > 50)) ` `            ``break``; ` ` `  `        ``for` `(``int` `i = 0; i < length; ++i) ` `            ``cout << s[i]; ` `        ``++j; ` `    ``} ` ` `  `    ``return` `0; ` `} `

Output:

Note: There is no output in the above program since it is a case of failure.

My Personal Notes arrow_drop_up Budding Web DeveloperKeen learnerAverage CoderDancer&Social Activist

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.
{"ft_lang_label":"__label__en","ft_lang_prob":0.5731849,"math_prob":0.86779493,"size":2711,"snap":"2019-35-2019-39","text_gpt3_token_len":762,"char_repetition_ratio":0.1666051,"word_repetition_ratio":0.3075269,"special_character_ratio":0.3046846,"punctuation_ratio":0.13279678,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9793567,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-08-24T15:29:35Z\",\"WARC-Record-ID\":\"<urn:uuid:af57d19f-2daa-466f-ad80-34cfb84a0669>\",\"Content-Length\":\"98624\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:def18e64-7909-4fab-8269-9513aa3739ec>\",\"WARC-Concurrent-To\":\"<urn:uuid:a879deac-c828-4f0c-bd47-b74c06f878a2>\",\"WARC-IP-Address\":\"23.221.72.19\",\"WARC-Target-URI\":\"https://www.geeksforgeeks.org/c32rtomb-function-in-c-c/\",\"WARC-Payload-Digest\":\"sha1:NHRSVAYGL7KKZNWYIAOZDPM3TZ2IUQF3\",\"WARC-Block-Digest\":\"sha1:AP6E5NV4PA45YYFDS3OO46TYI3K72LZN\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-35/CC-MAIN-2019-35_segments_1566027321160.93_warc_CC-MAIN-20190824152236-20190824174236-00139.warc.gz\"}"}