【问题标题】:C reading in utf characters from fileC从文件中读取utf字符
【发布时间】:2017-09-06 05:31:52
【问题描述】:
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。而其余的都是负数。

【问题讨论】:

  • 我认为这些字符属于扩展的 ASCII 字符,这意味着 ASCII 值大于 128。您需要一个最多可容纳 255 个的存储。char 类型不行。你需要 unsigned char 类型。

标签: c input ascii utf extended-ascii


【解决方案1】:

你应该使用 wchar_t 函数:putwchar(c)getwchar(c)fgetwc(file), 等等……

看看这个reference

【讨论】:

    猜你喜欢
    • 2015-05-20
    • 1970-01-01
    • 2010-12-25
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 2014-01-21
    • 2012-02-04
    • 1970-01-01
    相关资源
    最近更新 更多