×

Loading...
Ad by
  • 技多不压身,工到自然成:安省技工证书特训班,点击咨询报名!
Ad by
  • 技多不压身,工到自然成:安省技工证书特训班,点击咨询报名!

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++];