You are using char
which can only store values between -128
and +127
. Instead Use other data type to get much alrger range.
So instead of
char deci = 0;
use int
int deci = 0;
and even if it overflows you can use unsigned int
(As your code only reads non-negative values)
unsigned int = 0;
C Standard guarantees that char
must be at least 8 bits wide, short
and int
must be at least 16 bits wide, and long
must be at least 32 bits wide, and that sizeof (char) <= sizeof (short) <= sizeof (int) <= sizeof (long)
(same is true for the unsigned versions of those types).
int
may be anywhere from 16 to 64 bits wide depending on the platform.
Also There is another problem with your code that could result in fault in execution in future.
Your array subscript i
is char
and compiler should have given you the
Warning : array subscript has type 'char'.
It has given so because type char
can be signed or unsigned—it's up to the compiler. If char
is signed, then it's possible for i
to be negative, in which case accessing a negative array index leads to Undefined Behavior.
I highly recommend you to look at this answer to avoid common pitfall in future.
Tip: Always Format Your Code Properly, it would help you in visualising and also to others who are trying to find problem in it.
Downvoter Care To Explain Why he downvoted.