C从文件中读取utf字符

标签 c input ascii utf extended-ascii

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)、 等等...

看这个reference

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

相关文章:

CUDA:两个数字相加给出错误答案

c - 这个C程序有什么问题?

java - 输入错误。即使在接受新输入后仍然使用旧输入

css - 如何使输入/文本占据 Bootstrap 4 中 div 的整个宽度?

c# - Microsoft Visual Studio,如何编码以便 ASCII 显示在我的控制台应用程序上?

Python-在二进制文件中写入长串位

c - 按位运算符 : Printing the numbers 1 to 100 using bit manipulation

将带有负数的 Float 转换为 Int32 失败,C

javascript - 输入为空时如何停止发送

r - 从 'A' -'Z' 生成字符序列