为什么我这程序会弹出错误?该怎么修改呢?

#include <stdio.h>
#include <stdlib.h>
void main ()
{
int str;
char ch;
printf ("input :");
ch=getchar();

str=atoi(ch);
printf ("str=%c\n",str);

}

慕桂英546537
浏览 89回答 2
2回答

慕工程0101907

#include<stdio.h>voidmain(){chara='9';intb=a-'0';//intb=a;如果这样写,b的值是57,就不对了。但是都转换为57这样的asc码也可以作为一种加密方式,是否这样操作就由你决定。printf("%d\n",b);//这样输出的b为9,是整形的。}至于加密,规则没有规定,因为加密的时候只有规则是保密的才算是加密,所以没有统一规定,很简单的加密就是颠倒数字顺序,大写变小写,字符变代码(你也可以自己规定代码规则),加减数字,首末掉换。总之怎么弄的规则你来定。&nbsp;

函数式编程

不知道你要实现什么:按你的程序,这样改:#include <stdio.h>&nbsp;#include <stdlib.h>&nbsp;void main ()&nbsp;{&nbsp;int str;&nbsp;char ch;&nbsp;printf ("input :");&nbsp;ch=getchar();&nbsp;str=atoi(&ch);&nbsp;printf ("str=%c\n",str);&nbsp;}字符型转换成整型,这样改:#include <stdio.h>&nbsp;#include <stdlib.h>&nbsp;void main ()&nbsp;{&nbsp;int str;&nbsp;char ch;&nbsp;printf ("input :");&nbsp;ch=getchar();&nbsp;str=(int)ch;&nbsp;printf ("str=0x%x\n",str);&nbsp;}&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP