×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

See the code

int split(char* sLine, char* fields[], char delimit)
{
int count = 0, index = 0;
fields[count++] = sLine;
while (sLine[index] && sLine[index] != '\r' && sLine[index] != '\n') {
if (sLine[index] == delimit) { // find the delimitor
sLine[index++] = '\0';
if (sLine[index] == delimit)
fields[count++] = NULL;
else
fields[count++] = trim(&sLine[index++]);
}
else
index++;
}
return count; // now sLine was cut into a string array
}
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / how to get?
    I have a string, like "1060732951|0.00429|1|Default status|29576|6384",
    I want to get epoch=1060732951, second=0.00429, tmp=1,
    string = "Default status", in= 29576, out = 6384,

    how to get these using C.

    thanks.
    • See the code
      int split(char* sLine, char* fields[], char delimit)
      {
      int count = 0, index = 0;
      fields[count++] = sLine;
      while (sLine[index] && sLine[index] != '\r' && sLine[index] != '\n') {
      if (sLine[index] == delimit) { // find the delimitor
      sLine[index++] = '\0';
      if (sLine[index] == delimit)
      fields[count++] = NULL;
      else
      fields[count++] = trim(&sLine[index++]);
      }
      else
      index++;
      }
      return count; // now sLine was cut into a string array
      }
      • Some corrections
        Somehow, the cut-past lost some characters. The while-loop is supposed to be like
        while (sLine[index] && sLine[index] != '\n' && sLine[index] != '\r ')

        Also you might not need function "trim" if the leading spaces are not a problem. fields[count++] = &sLine[index++];