fork(3) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <wchar.h>
  4. #include <iconv.h>
  5. #include <errno.h>
  6.  
  7. #define BUFFER_SIZE 4096
  8.  
  9. static char* wchartoutf8(wchar_t* input) {
  10. char *output = malloc(BUFFER_SIZE);
  11. iconv_t foo = iconv_open("UTF-8", "WCHAR_T");
  12. size_t ilen = wcslen(input) * sizeof(wchar_t);
  13. size_t olen = BUFFER_SIZE;
  14. int r = iconv(foo, (char**)&input, &ilen, &output, &olen);
  15. if(r < 0)
  16. perror("iconv");
  17. printf("LEN=%d\n", r);
  18. return output;
  19. }
  20.  
  21. int main()
  22. {
  23. printf("str: %s\n", wchartoutf8(L"чёзанахуй?"));
  24. return 0;
  25. }
Success #stdin #stdout 0s 9456KB
stdin
Standard input is empty
stdout
LEN=0
str: