mbsrtowcs.c 557 B

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