Reading unicode file in c
c, file, unicode
Solution
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);
}
Problem
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; } ```