回答編集履歴
1
strtok例を追加
answer
CHANGED
@@ -3,4 +3,19 @@
|
|
3
3
|
- strtok関数でカンマ毎に(16進表記)文字列を分ける:[strtok()関数でカンマ区切りデータを分ける](http://garchiving.com/comma-separated-by-arduino/)
|
4
4
|
- strtol関数で(16進表記)文字列を数値に変換する:[Topic: Converting Strings to Longs](http://forum.arduino.cc/index.php?topic=44922.0)
|
5
5
|
|
6
|
-
各関数の使い方は、ArduinoやC言語の入門サイトなどを参考にしてください。
|
6
|
+
各関数の使い方は、ArduinoやC言語の入門サイトなどを参考にしてください。
|
7
|
+
|
8
|
+
以下はstrtokでカンマ毎に文字列を切り出す例です。
|
9
|
+
```C
|
10
|
+
#include <stdio.h>
|
11
|
+
#include <stdlib.h>
|
12
|
+
int main(void) {
|
13
|
+
char str[] = "123,012";
|
14
|
+
char *tok = strtok( str, "," );
|
15
|
+
while( tok){
|
16
|
+
printf( "%d\n", strtol( tok , NULL, 16));
|
17
|
+
tok = strtok( NULL, "," );
|
18
|
+
}
|
19
|
+
return 0;
|
20
|
+
}
|
21
|
+
```
|