View Single Post
Old 09-17-10, 12:18 PM   #2
FlakMagnet
Registered User
 
FlakMagnet's Avatar
 
Join Date: Mar 2005
Location: Farnborough, UK
Posts: 335
Default Re: C programming issue

In C, you cannot perform a switch on character arrays, so you will need to convert your array into an integer value.

To do this, try something like the following. I haven't had a chance to see if the following compiled, but it should give you the idea.

int ConvertToInt(char val[])
{
int result = 0;

for (int pos = 0; pos < 5; pos++)
{
result = result << 1;

if (val[pos] == '1')
{
result |= 1;
}
}

return result;
}

You can then use this method to convert your array to a value and use it like this :

switch (ConvertToInt(sensor_values))
{
case 0x03: // 00011 in Hex.
// do somehing
break;
case 0x18: // 11000 in hex.
// do something else
break;
default:
break;
}

Hope that helps.
__________________
ASUS P6T Deluxe V2 | i7 920 @ 3.6GHz
POV GTX480 | 6GB Patriot DDR3 @1443
X-Fi Fatal1ty Pro | 120GB OCZ Vertex SSD
2xSamsung 7200 750GB RAID 0| Akasa Eclipse 62
FlakMagnet is offline   Reply With Quote