您的位置:首页 > 编程语言 > C语言/C++

ASCII码转换

2016-08-18 21:04 288 查看
想做一个加密信息的小程序,第一个想到的办法就是用书上看到的ASCII码,虽然不是很成功。还是留作纪念吧。

/*************************
*ASCII transformation   *
*                 by:ZCB*
*************************/

#include<stdio.h>
#include<stdlib.h>

int main(void)
{
int a = 0;
int b = 0;
char c = 0;
printf("If you want to convert a decimal number to ASCII characters,please input 1.\n");
printf("If you want to convert ASCII characters to a decimal number,please input 2.\n");
scanf("%d",&a);
if(a == 1)
{
printf("Now we will convert a decimal number to ASCII characters.\nPlease i
98de
nput a decimal number.\n");
scanf("%d",&b);
if(b >= 0&&b <= 127)
printf("%c",b);
else
printf("You are so naughty.\nPlease input 1 or 2 next time.\n");
}
else if(a == 2)
{
printf("Now we will convert ASCII characters to a decimal number.\nPlease input ASCII characters.\n");
fflush(stdin);
scanf("%c",&c);
if(c >= (char)0&&c <= (char)127)
printf("%d",c);
else
printf("You are so naughty.\nPlease input 1 or 2 next time.\n");
}
else
{
printf("You are so naughty.\nPlease input 1 or 2 next time.\n");
}
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C语言