title: C strtok and strcpy
body: <p>I have a text file, similar to the following:</p>
  
  <pre><code>Name1: ID1
  Name2: ID2
  Name3: ID3
  </code></pre>
  
  <p>I am trying to parse it to get</p>
  
  <pre><code>Name1
  Name2
  Name3
  </code></pre>
  
  <p>stored in a variable.</p>
  
  <p>I wrote the following function:</p>
  
  <pre><code>/*
   *  filename    Name of file to read
   *  result      The result will be stored here
   */
  
  void readlist(char* filename, char* result) {
      FILE *fp;
      char buffer[2048];
      memset((void *)result, '\0', BUFFER_SIZE);
  
      fp = fopen(filename, "r");
  
      while (fgets(buffer, sizeof(buffer), fp)) {
          char *token = NULL;
          token = strtok( buffer, ":" );
          strcat(result, token);
      }
  
      fclose(fp);
  }
  </code></pre>
  
  <p>However when I call it:</p>
  
  <pre><code>char result[2048];
  readlist("test.txt", result);
  printf("%s", result);
  </code></pre>
  
  <p>I'm getting an empty output. It seems that strtok() messes up the data, but I might be wrong.</p>
  
  <p>What am I doing wrong here?</p>
  
  <p>Thank you in advance!</p>