mbsrtowcs.c 608 B

12345678910111213141516171819202122232425
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <wchar.h>
  4. #include "test_helpers.h"
  5. void print_as_wide(const char* mbstr)
  6. {
  7. mbstate_t state;
  8. memset(&state, 0, sizeof state);
  9. size_t len = 1 + mbsrtowcs(NULL, &mbstr, 0, &state);
  10. wchar_t wstr[len];
  11. mbsrtowcs(&wstr[0], &mbstr, len, &state);
  12. //Should be 5
  13. printf("The length, including '\\0': %li \n",len);
  14. //missing wprintf to print this wide string
  15. //wprintf(L"The wide string: %ls \n", &wstr[0]);
  16. }
  17. int main(void) {
  18. const char* mbstr = u8"z\u00df\u6c34\U0001f34c"; // or u8"zß水🍌"
  19. print_as_wide(mbstr);
  20. }