I have an list of numbers as an ascii string that I need to split by a token and store the result in an array of chars. However I want the value of the char to be the number the ascii text represents. i.e. if the text within the tokens is '240' I want the value of the char to be 0xf0. The main problem is I don't know how to split the strings and I don't know how to convert the value to what I want.
This is an example input
string s= "0,0,0,0,240,240,240,240,0,0,0,0,255,255,255,255,0 ,0,0,0,80,80,80,80,0,0,0,0,80,80,80,80"
this is the output that I would want
char data[4][8] =
{0x0,0x0,0x0,0x0,0xf0,0xf0,0xf0,0xf0,
0x0,0x0,0x0,0x0,0xff,0xff,0xff,0xff,
0x0,0x0,0x0,0x0,0x50,0x50,0x50,0x50,
0x0,0x0,0x0,0x0,0x50,0x50,0x50,0x50};
As of now this is how I would approach it
Expand|Select|Wrap|Line Numbers
- string s= "0,0,0,0,240,240,240,240,0,0,0,0,255,255,255,255,0,0,0,0,80,80,80,80,0,0,0,0,80,80,80,80";
- char data[4][8];
- int i,j;
- char result;
- char * tok;
- tok = strtok(s,',');
- for(i=0;i<4;i++)
- for(j=0;j<8;j++)
- {
- if(tok != NULL) {
- //convert tok into it's value as a char somehow and store it in result
- char[i][j] = result;
- tok = strtok(NULL,',');
- }
- }