如何将字符串拆分成数组 - (棘手的版本)

时间:2017-01-10 19:19:52

标签: c csv arduino esp8266 spiffs

如何将字符串拆分为表格?
我正在使用的字符串是Arduino FS中文件的内容。我使用SPIFSS.open()创建了这个字符串 我的目标是从文件中读取数据并将其放入表中。分离字符是分隔符&#34 ;;"就像在.csv文件中一样。

  

达成目标:
  t [1] =这里
  t [2] =有些人   T [3] =样品
  T [4] = 100
  ...

File cfg_s1 = SPIFFS.open("/cfg_s1.txt", "r");
if (!cfg_s1) {
  Serial.println("file open failed");
}

// version below with char is working correctly
//char sz[] = "Here; is some; sample;100;data;1.414;1020";

// version with string is not working. "sz" is the content of cfg_s1.txt file 
String sz;
sz=cfg_s1.readString();

void setup()
{
 Serial.begin(115200);
 char *p = sz;
 char *str;
 String t[10];
 int i = 1;

 while ((str = strtok_r(p, ";", &p)) != NULL){
   t[i]=str;
   Serial.println(t[i]);
   i++;
 }
Serial.println(t[2]);
}


void loop()
{

}

错误:"无法转换'字符串'到#char;'在初始化"

0 个答案:

没有答案