gpt4 book ai didi

c - mbtowc : howto determine number of characters to skip if null character is read

转载 作者:行者123 更新时间:2023-11-30 15:01:06 38 4
gpt4 key购买 nike

根据 C99 规范 mbrtowc函数返回0

if the next n or fewer bytes complete the multibyte character that corresponds to the null wide character (which is the value stored).

在编码的空字符之后立即继续读取输入的最佳方法是什么?

我当前的解决方案是使用给定的编码转换空宽字符,以确定下次调用mbrtowc时要跳过的输入字节数。 。但可能有一种更优雅的方法来做到这一点。

此外,我想知道 mbrtowc 这种行为背后的理由是什么可能是。

最佳答案

一个字节。无论移位状态如何,空字节始终表示空字符,并且不能作为多字节字符的一部分参与。其来源是:

5.2.1.2 Multibyte characters

...

  • A byte with all bits zero shall be interpreted as a null character independent of shift state. Such a byte shall not occur as part of any other multibyte character.

关于c - mbtowc : howto determine number of characters to skip if null character is read,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41664680/

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