Each time i set a value in b after a, the value is reset to 0 in a. In other words, as the code goes, no matter what i input in a it will be always 0 after the second scanf function.
EDIT: I need to use b as char type for the essay, for memory efficiency, so i can't set b to int, but i need to input integer in there.
EDIT2: I need to input an integer in b, example for an input:
1
2
from that point if i
printf("%d",a);
i get 0.
unsigned short a;
char b;
scanf("%hu",&a);
scanf("%d",&b);
"%d"
inscanf()
expects a pointer toint
. You are passing a pointer tochar
and invoking Undefined Behaviour. Tryint b;
. – pmgCHAR_MIN
(-127) andCHAR_MAX
(127)? Or, to pose a general question: What is the range of the second value you're reading? – meaning-mattersb
. This can only be a single digit in the range 0..9 which then needs an adjustment from its character value (usually ASCII), such as withscanf(" %c", &b); b -= '0';
. – Weather Vane