I am programming in C and I have a character array filled with letters/numbers. I want to compare the first two values together as one number or combo.
char values[8];
//a value of this might be 245756
switch (values[0 and 1]){
case 24:
do something;
case 45:
do something else;
}
Do I have to concatenate or what if I want to combine the two values and then see if they equal some set of combinations?
Thanks!
Please let me know if I am being unclear.
I’m assuming that your
chararray holds the characters'2','4', etc.In which case, you can convert a character to its equivalent integer value as follows:
So all you need to do is perform this calculation for each of
values[0]andvalues[1], and then perform the base-10 maths to combine these into a single integer value.If your
chararray already holds the integer value for each digit, then you can of course skip the conversion, and jump straight to the base-10 maths.