#include <Streaming.h>
void setup()
{
Serial.begin(115200);
String s = "0,2,1,12";
const int bsize = 16;
char ts[bsize];
//s.toCharArray(ts, s.length());
s.toCharArray(ts, bsize);
//char ts[] = "0,2,1,12";
int valueArray[8] = { 5,5,5,5,5,5,5,5 };
splitValue(ts, valueArray, 8);
for (int i=0; i<8; i++)
Serial << valueArray[i] << "\n";
}
void splitValue(char *valueString, int * valueArray, int ArraySize)
{
int i=0;
char *tmp;
tmp = strtok(valueString, ",");
while(tmp && i<ArraySize) {
//Serial << tmp << "\n";
valueArray[i] = atoi(tmp);
//Serial << valueArray[i] << "\n";
i++;
tmp = strtok(NULL, ",");
}
while(i< ArraySize)
valueArray[i++] = 0;
}
void loop()
{
}
沒有留言:
張貼留言