Reading unicode file in c

前端 未结 1 835
花落未央
花落未央 2021-01-21 02:08

I just want to read read unicode text file in normal c. Following code is not working for same,

#include

int main()
{
        FILE *ptr_file;
            


        
相关标签:
1条回答
  • 2021-01-21 02:46

    Try this:

    #include <locale.h>
    #include <stdio.h>
    #include <wchar.h>
    
    int main()
    {
        FILE *input;
        wchar_t buf[1000];
    
        setlocale(LC_CTYPE,"it_IT.UTF-8");   // put your locale here
    
        if ((input = fopen("input.txt","r")) == NULL)
             return 1;
    
        while (fgetws(buf,1000,input)!=NULL) 
            wprintf(L"%s",buf);
    
        fclose(input);
    }
    
    0 讨论(0)
提交回复
热议问题