t_mbstowcs.c 395 B

123456789101112131415161718
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. int main(int argc, char * argv[]) {
  5. size_t req = mbstowcs(NULL, argv[1], 0);
  6. wchar_t * dest = malloc(sizeof(wchar_t) * req);
  7. mbstowcs(dest, argv[1], req+1);
  8. for (size_t i = 0; i < req; ++i) {
  9. char tmp[8];
  10. wchar_t in[] = {dest[i], L'\0'};
  11. wcstombs(tmp, in, 8);
  12. fprintf(stdout, "U+%4x %s\n", dest[i], tmp);
  13. }
  14. return 0;
  15. }