title: reading data from mmap and string manipulation in c++
body: <p>I'm trying to read a bunch of data from mmap and this functions as I expect it to.</p>
  
  <pre><code>size_t filesize = getFilesize(argv[1]);
  int fd = open(argv[1], O_RDONLY, 0);
  assert(fd != -1);
  char* mmappedData = static_cast&lt;char*&gt;(mmap(NULL, filesize, PROT_READ, MAP_PRIVATE | MAP_POPULATE, fd, 0));
  assert(mmappedData != MAP_FAILED);
  
  char *strmmap = strdup(mmappedData);
  char *strData = strtok(strmmap, "#");
  strData = strtok(strData, ";");
  string rid;
  unsigned long int timestamp;
  string tid;
  string TIMESTAMP;
  </code></pre>
  
  <p>Here is some of the test data from mmap</p>
  
  <pre><code>1497648366867,{75: 5, 76: 2, 77: 4, 78: 1, 79: 0, 80: 3}
  79;ns]D;1497648366929
  77;_1[A;1497648366940
  78;~E=);1497648366940
  78;~E=);1497648366943
  77;_1[A;1497648366947
  80;QXD=;1497648366991
  78;E}Hy;1497648366991
  78;E}Hy;1497648366997
  80;QXD=;1497648367004
  </code></pre>
  
  <p>I'm struggling with the string manipulation </p>
  
  <pre><code>    do{
          timestamp = strtoul(strData, NULL, 0);
          strData = strtok(NULL, ";");
          tid = strData;
          cout &lt;&lt;"tid:"&lt;&lt;tid &lt;&lt; '\t' &lt;&lt; "timestamp:"&lt;&lt;timestamp &lt;&lt;endl;
      } while((strData = strtok(NULL, ";")) != NULL);
      cout &lt;&lt;"================================="&lt;&lt;endl;
  </code></pre>
  
  <p>the timestamp variable returns the timestamp perfectly for the first line of the test_data, but fails for the rest of it. </p>
  
  <p>What I'm trying to achieve is something like this, assuming lines is an array of the data split with semicolon if there exist three data points, or split with comma if there are two data points. Here is a prototype in python.</p>
  
  <pre><code>for l in range(len(lines)):
   if len(line[l]) == 2:
     timestamp = line[l][0]
     tids = line[l][1]
   else:
     tid = line[l][0]
     rid = line[l][1]
     timestamp = line[l][3]
  </code></pre>