c reading non ASCII characters

前端 未结 3 706
星月不相逢
星月不相逢 2021-01-13 09:58

I am parsing a file that involves characters such as æ ø å. If we assume I have stored a line of the text file as follows<

3条回答
  •  逝去的感伤
    2021-01-13 10:21

    The C standard IO library can only read bytes. Your file probably contains multibyte characters, encoded with UTF8 or some other encoding. You'll need a library for interpreting such files.

    It is possible that your file contains Latin1 text, in which case characters are bytes. In this case, you cannot use isgraph unless you have the proper locale set.

    Bottom line: find the encoding used in your file. Then read it accordingly. In any case, plain C does not know about encodings.

提交回复
热议问题