为什么printf(“%c”,1)返回笑脸而不是1的编码char [英] Why does printf( "%c", 1) return smiley face instead of coded char for 1

查看:151
本文介绍了为什么printf(“%c”,1)返回笑脸而不是1的编码char的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

#include <stdio.h>

int x,y;

int main( void )
{
    for ( x = 0; x < 10; x++, printf( "\n" ) )
        for ( y = 0; y < 10; y++ )
            printf( "%c", 1 );

    return 0;
}

它返回笑脸。我到处搜索了笑脸的代码或1的代码,但是我找不到任何链接,也找不到任何解释,当1的ascii代码为SOH时,为什么1的char值返回笑脸。我研究了这个问题的答案,但没有找到任何解释原因的答案。

It returns smiley faces. I searched everywhere for a code for smiley face or a code for 1 but I didn't manage to find any links whatsoever or any explanation why char value for 1 returns smiley face, when the ascii code for 1 is SOH. I researched answers for this question but I didn't find any answers that explain why this happens.

推荐答案

终端。例如,在我的OS X默认终端上,没有字符输出。

The output varies among different terminals. For example, on my OS X default terminal, no characters are output.

在您的情况下,输出大概是由于某些历史原因。简而言之,这是因为代码页437是将字符 0x01 映射到 U + 263A 的代码页, MS-DOS。

In your case, is output presumably due to some historical reasons. In short, this is because code page 437, which maps byte 0x01 to U+263A, is the character set of MS-DOS.

这篇关于为什么printf(“%c”,1)返回笑脸而不是1的编码char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆