从URL

2017-04-09 38 views
-1

我从服务器获取URL输入如下接收参数:从URL

http://10.0.0.70/distance=150/angle=60 

现在我怎么可以从这个URL获得的距离和角度参数,并将其存储到另一个变量?我不得不在Arduino编程语言中使用它。

回答

1

这应该工作

char str[] = "http://10.0.0.70/distance=150/angle=60"; 
char * pch; 
char *ptr; 
long ret; 

pch = strchr(str,'='); // find '=' 
ret = strtoul(pch, &ptr, 10); // take the number after it (here ret = 150) 

pch = strchr(pch+1,'='); // find the next '=' 
ret = strtoul(pch, &ptr, 10); // take the number after it (here ret = 60)