简体   繁体   中英

Reading unicode file in c

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

#include<stdio.h>

int main()
{
        FILE *ptr_file;
        char buf[1000];

        ptr_file =fopen("input.txt","r");
        if (!ptr_file)
            return 1;

        while (fgets(buf,1000, ptr_file)!=NULL)
            printf("%s",buf);

    fclose(ptr_file);
        return 0;
}

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM