在C语言中为了方便快捷地实现ascii码的查询,我们可以利用函数的声明和定义来实现
新建一个项目
头文件:
#pragma once
int ascii(char n);
源文件:因为要使用printf,还需要包含头文件
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int ascii(char n)
{
printf("%c的ascii码对应值为%d\n", n, n);
return 0;
}
输出案例:包含自己写的头文件需要用‘ ’,而包含C语言官方库是需要<>尖括号。
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include "ascii.h"
int main()
{
ascii('t');
}
输出结果。
这样就实现了ascii码的快速查询。