You want something like:
if(key == '1' || key == '2' || ....
Why in %DEITY%'s name would you want to do it that way?
Because it will work fine and is easily derivable from the basic rules of the C language? Something which the original poster is clearly having trouble with.
Sure, it's a bit more typing than some other solutions, but if it takes 3 us on an AVR instead of 0.5 us, of what concern is that when the human is hitting a couple of buttons a second?
And it saves you from having to know that the digits have consecutive codes in ASCII, or that there is a library with an isdigit() function. Those can come later.
Incidentally, I tried compiling:
int isdig(char c){
return
(c == '0') || (c == '1') || (c == '2') || (c == '3') || (c == '4') ||
(c == '5') || (c == '6') || (c == '7') || (c == '8') || (c == '9');
}
gcc -O for ARM gave:
00000000 <isdig>:
0: 3830 subs r0, #48 ; 0x30
2: b2c0 uxtb r0, r0
4: 2809 cmp r0, #9
6: bf8c ite hi
8: 2000 movhi r0, #0
a: 2001 movls r0, #1
c: 4770 bx lr
gcc -O for RISC-V gave:
0000000000000000 <isdig>:
0: fd05051b addiw a0,a0,-48
4: 0ff57513 andi a0,a0,255
8: 00a53513 sltiu a0,a0,10
c: 8082 ret
gcc -O for AVR gave:
00000000 <isdig>:
0: 90 ed ldi r25, 0xD0 ; 208
2: 98 0f add r25, r24
4: 81 e0 ldi r24, 0x01 ; 1
6: 9a 30 cpi r25, 0x0A ; 10
8: 08 f0 brcs .+2 ; 0xc <__zero_reg__+0xb>
a: 80 e0 ldi r24, 0x00 ; 0
c: 08 95 ret
Even gcc -O for x86_64 gave:
0000000000000000 <isdig>:
0: 83 ef 30 sub $0x30,%edi
3: 40 80 ff 09 cmp $0x9,%dil
7: 0f 96 c0 setbe %al
a: 0f b6 c0 movzbl %al,%eax
d: c3 retq
So, there's no need to actually know the values are dense in ASCII and optimise it yourself, because the compiler is perfectly capable of doing it for you, even at only -O1.