C语言常用函数-toascii()将字符转换为ASCII码函数

演示版本

VS2013

  • toascii()函数

toascii函数用于把一个非ASCII字符转换成ASCII码,其实就是把八位二进制数的最高位变成0。

语法

int toascii(int ch);

toascii函数的语法参数说明如下:

参数ch为待转换的字符。

toascii函数的返回值:转换后的字符。

示例

本示例演示用toascii函数把一个非ASCII字符转换为ASCII码。其具体代码如下:

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

int main()
{
    int ch1, ch2;
    ch1 = 'a' + 128;
    ch2 = toascii(ch1);//转换为ASCII字符
    printf("transform %c to %c
", ch1, ch2);

    return 0;
}

阿飞

2021年7月27日

原文地址:https://www.cnblogs.com/nxopen2018/p/15067981.html