曲径通幽论坛

标题: toascii() -- 将整数转换为 ASCII [打印本页]

作者: beyes    时间: 2011-12-18 12:28
标题: toascii() -- 将整数转换为 ASCII
toascii() 函数原型如下:
[C++] 纯文本查看 复制代码
#include <ctype.h>
       int toascii(int c);

该函数将参数 c 转换成 7 位的无符号字符型(unsigned char)值,第 8 位置 0,这个值即会被转换为 ASCII 字符。

测试代码:
[C++] 纯文本查看 复制代码


#include <stdio.h>
#include <ctype.h>


int main()
{
        int a = 212;
        char b;


        printf ("before toascii() : a value = %d(%c)\n", a, a);


        b = toascii(a);
        printf ("after toascii() : a value = %d(%c)\n", b, b);


        return 0;
}

运行输出:
./toascii
before toascii() : a value = 212(�)
after toascii() : a value = 84(T)





欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2