无效的输入值,而使用CHAR和scanf"%HHU" [英] Invalid input value while using char and scanf "%hhu"

查看:242
本文介绍了无效的输入值,而使用CHAR和scanf"%HHU"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此​​,这是code

So this is the code

void main()
{
  unsigned char n,t;
  scanf("%hhu %hhu",&n,&t);
  printf("%hhu %hhu",n,t);
}

问题是,当我输入分别为5和1,输出是的 T 的0和1 0的 N 的1。然而,当我改变从CHAR为int /无符号的类型,输出是正确的预期:5和1

The problem is when I input 5 and 1 respectively, the output is 0 and 1. 0 for n and 1 for t. However, when I changed the type from char to int/unsigned, the output is right as expected: 5 and 1.

问题是,为什么要求(数字)用char输入给无效值?

The question is why asking for (number) input with char gives invalid value?

推荐答案

INT主要(无效)

scanf("%hhu %hhu",&n,&t);

在这里---------- ^ ^ ------ 无符号字符* 有望

同为的printf(%HHU%HHU,N,T);

所以更改

char n,t;

unsigned char型N,T;

这篇关于无效的输入值,而使用CHAR和scanf"%HHU"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆