gpt4 book ai didi

C从文件中读取utf字符

转载 作者:行者123 更新时间:2023-11-30 14:58:27 25 4
gpt4 key购买 nike

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 值转换为十六进制的函数。但是在处理这些字符时,我得到负值作为它们的输入。

-52124-92-63-105-91-10-36 这些是我读取它们并将它们存储到数组中然后打印出来时得到的值。 | 的 |作为一个ascii字符是124。而其余的都是负数。

最佳答案

您应该使用 wchar_t 函数:putwchar(c)getwchar(c)fgetwc(file)、 等等...

看这个reference

关于C从文件中读取utf字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43335589/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com