fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <wchar.h>
  5. #include <locale.h>
  6.  
  7. #define MAXSZ 128
  8.  
  9. int main()
  10. {
  11. setlocale(LC_ALL,"Chinese_Taiwan.950");
  12. const char* file="x.txt";
  13. FILE *fp= fopen( file,"r");
  14. if( fp == NULL){
  15. perror( file);
  16. return -1;
  17. }
  18. char data_buf[MAXSZ];
  19. wchar_t w_buf[MAXSZ];
  20. while(fgets(data_buf,MAXSZ,fp)!=NULL){
  21. int sz=strlen(data_buf);
  22. if(data_buf[sz-1]=='\n'){
  23. data_buf[sz-1]='\0';
  24. }
  25. if(data_buf[0]=='\0'){
  26. continue;
  27. }
  28. if(mbstowcs(w_buf,data_buf,MAXSZ)==-1){
  29. perror("mbstowcs error");
  30. return -1;
  31. }
  32. printf("wcslen=%d--> %S ; %C",wcslen(w_buf),w_buf,w_buf[0]);
  33. }
  34. return 0;
  35. }
Runtime error #stdin #stdout #stderr 0s 17704KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
x.txt: No such file or directory