目录
- 1. 截取
- 2. 转换
1. 截取
以SW,33,55,78,\r\n为例
char* pa,pb,pc,pd,pe;
uint8_t usart5_rxsavebuf[] = "SW,12,32,33,55,78,\r\n";strtok((char *)usart5_rxsavebuf, ",");
pa = strtok(NULL, ",");
pb = strtok(NULL, ",");
pc = strtok(NULL, ",");
pd = strtok(NULL, ",");
pe = strtok(NULL, ",");
得到结果:
pa = “SW”;
pb = “33”;
pc = “55”;
pd = “78”;
pe = “\r\n”;
2. 转换
将得到的 char 类型数据转换为double类型或者int类型,所用函数atoi和strtod。
int atoi (const char *__nptr);
double strtod (const char *__restrict __n, char **__restrict __end_PTR);
double get_data;char* end;
get_data = strtod(pb, &end);
得到 get_data = 33;