在阅读中联code文件 [英] Reading unicode file in c
本文介绍了在阅读中联code文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是想读读在正常中联code文本文件。
继code未工作一样,
#包括LT&;&stdio.h中GT;诠释的main()
{
FILE * ptr_file;
焦炭BUF [1000]; ptr_file = FOPEN(input.txt的,R);
如果(!ptr_file)
返回1; 而(与fgets(BUF,1000,ptr_file)!= NULL)
的printf(%S,BUF); FCLOSE(ptr_file);
返回0;
}
解决方案
试试这个:
的#include<&locale.h文件GT;
#包括LT&;&stdio.h中GT;
#包括LT&;&wchar.h GT;诠释的main()
{
FILE *输入;
wchar_t的BUF [1000]; 的setlocale(LC_CTYPEit_IT.UTF-8); //把你这里的语言环境 如果((输入= FOPEN(input.txt的,R))== NULL)
返回1; 而(fgetws(BUF,1000,输入)!= NULL)
wprintf(L%S,BUF); fclose函数(输入);
}
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);
}
这篇关于在阅读中联code文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文