/*
C program for splitting a string
using strtok()
*/
char* tok;
const char s[4] = " ";
char gfg[100] = "1997 Ford E350 ac 3000.00";
//#include <stdio.h> //possono essere omessi
//#include <string.h> //possono essere omessi
void setup() {
Serial.begin(9600);
// Declaration of string
// Information to be converted into CSV file
//char gfg[100] = "1997 Ford E350 ac 3000.00";
// Declaration of delimiter
// const char s[4] = " ";
//char* tok;
}
void loop()
{
//primo esempio
/*
char str[] = "Geeks-for-Geeks";
// Returns first token
char* token = strtok(str, " - ");
// Keep printing tokens while one of the
// delimiters present in str[].
while (token != NULL) {
Serial.println(token);
//Serial.println("% s\n", token);
token = strtok(NULL, " - ");
}
*/
//secondo esempio
/*
// Declaration of string
char gfg[100] = " Geeks - for - geeks - Contribute";
// Declaration of delimiter
const char s[4] = "-";
char* tok;
// Use of strtok
// get first token
tok = strtok(gfg, s);
// Checks for delimiter
while (tok != 0)
{
Serial.println(tok);
//printf(" %s\n", tok);
// Use of strtok
// go through other tokens
tok = strtok(0, s);
}
*/
//terzo esempio
// Declaration of string
// Information to be converted into CSV file
//char gfg[100] = "1997 Ford E350 ac 3000.00";
Serial.println(gfg);
// Declaration of delimiter
//const char s[4] = " ";
//char* tok;
// Use of strtok
// get first token
tok = strtok(gfg, s);
//Serial.println(tok);
// Checks for delimiter
while (tok != 0) {
Serial.println(tok);
delay(2000);
// Use of strtok
// go through other tokens
tok = strtok(0, s);
}
}