gpt4 book ai didi

c++ - 'isprint' 在 solaris 上为不可打印的字符返回 true

转载 作者:太空狗 更新时间:2023-10-29 23:29:56 25 4
gpt4 key购买 nike

我们有一个包含字符流的字符缓冲区。我们一次读取每个字符并使用 isprint 检查它。在某些时候阅读 isprint 时,对于不可打印的字符返回 true。我们打印了该字符的十进制值 - -92 - 但 isprint 在 Solaris 上为此返回 TRUE。

代码:

for (int lix = 0; lix < l_len; ++lix) {
int lch = l_buf[lix];
if (isprint(lch) && !isspace(lch)) {
fputc(lch, l_fp);
}
else {
fprintf(l_fp, "\\%03o", lch);
}
}
  • l_bufconst char* 类型,包含字符流。
  • 此缓冲区中的数据来自套接字读取。
  • 同样的代码在 AIX 上运行良好;即,对于缓冲区中特定索引上的字符,isprint 在 AIX 上返回 false,在 Solaris 上返回 true

最佳答案

如果类型为 int 的函数 isprint() 的参数不能表示为 unsigned char,则行为未定义> 或等于 EOF。

7.4 Character handling

  1. The header declares several functions useful for classifying and mapping characters. In all cases the argument is an int, the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF. If the argument has any other value, the behavior is undefined.

关于c++ - 'isprint' 在 solaris 上为不可打印的字符返回 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36279823/

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