数据类型带来的问题
#include <stdio.h>int main()
{
unsigned char cm=0;
float in;
float lb;
unsigned char kg=0;
char name={'A'};
printf("name address is %p\n",&name);
printf("cm address is %p\n",&cm);
printf("kg address is %p\n",&kg);
printf("请输入你的姓名:");
scanf("%s",&name);
printf("%s\n",name);
printf("请输入你的身高(cm):");
scanf("%d",&cm);
printf("请输入你的体重(kg):");
scanf("%d",&kg);
in=(cm-0.0)*1/3;
lb=kg*1.45;
printf("%s的身高是%.2f(in),体重是%.2f(lb)",name,in,lb);
}
抱歉楼主无法添加代码文字,给大家带来不便
问题:
为什么在调用完scanf("%d",&kg);我的cm变量里的内容总会变为0? unsigned char kg=0;好像不能用%d 来调用具体的你查一下 嗯嗯,你说的对应该用%hhu来格式化读取 转载:https://www.cnblogs.com/ayanmw/p/3477248.html
出处:http://www.cnblogs.com/ayanmw
页:
[1]