[英]C reading in utf characters from file
wchar_t c;
printf("Please enter file path for the input file\n");
FILE *file;
char fileName[100];
scanf("%s",fileName);
file = fopen(fileName, "rb");
if(file == NULL){
printf("File not found program will now end \n");
exit(1);
}
while ((c = fgetc(file)) != EOF){
putchar(c);
asciiMessage[i] = c;
//cypher[i] = c;
i++;
}
我正在使用诸如Ì|€Á¥öÜ这样的输入来接收文件。 我如何将这些字符读入我的c程序。 我有一个将ASCII值转换为十六进制的函数。 但是通过处理这些字符,我得到了负值作为输入。
-52 124 -92 -63 -105 -91 -10 -36这些是我读取它们并将它们存储到数组中然后打印出来时所得到的值。 | 是ascii字符是124。其余的都是负数。
您应该使用wchar_t函数: putwchar(c)
, getwchar(c)
, fgetwc(file)
等...
看这个参考
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.