char
means that it consists of 1 character from supported characters in any specific language. -2
isn't 1 character, its a string
because it consist of sequence of characters e.g., '-'
and '1'
. So what your code is doing is doing the right thing.
Now, given that you really need characters to store your digits, then you have to map your negative value on to some other characters. Digits from 0..9
are actually ascci # 48..57
. So what you can do is pic 10 consecutive characters from the ascci table and treat them as -ve. Lets say you pick a .. i as your -ve numbers then a = -1, b = -2 and so on ...
Keep in mind that since you are using character, you can't deal with two digit numbers as long as you treat each number as an individual character. Then you have to handle all "decimal" operations.