title: Saving new points in time with ctime overwrites the old strings?
body: <p>Preface: I've been learning C this past summer and only recently started learning C++ so I don't know very much of it yet.</p>
  
  <p>I've been trying to write a C/C++ program that recognizes right and left mouse clicks in windows and saves which button was clicked and when into an array of pointers to strings <code>char **clicks</code>. I'm organizing it as a sequence like: button, time, button, time...</p>
  
  <p>Whenever a mouseclick is detected, it takes either "R" or "L" and does this:</p>
  
  <pre><code>void writeClick(char *button) {
      static char **tracker = clicks;
      *tracker = button;
      tracker++;
      time_t seconds = time(NULL);
      *tracker = ctime(&amp;seconds);
      tracker++;
  }
  </code></pre>
  
  <p>My question: The issue you may have noticed is that each array element with the time will be pointing to the same string. The result is that the time will update on each mouse click, but it will only remember the last saved time. I figured I could solve the problem with <code>strcpy</code>, but if I want to save multiple strings then won't I need a new variable for each string? Or a new memory location each time or something? How should I do this?</p>
  
  <p>I tried using <code>strcpy</code> like so:</p>
  
  <pre><code>strcpy(*tracker, ctime(&amp;seconds));
  </code></pre>
  
  <p>But at the second click my program crashes and I'm not sure why.</p>
  
  <p>Other information that may be useful:</p>
  
  <p>I'm planning on sending the data into VBA because I want to turn it into an Excel spreadsheet.</p>
  
  <p>I've yet to write the part of my code that dynamically increases the array whenever it gets full, but at the moment it's large enough (50 elements) to contain the data for a few clicks without crashing, so I know that's probably not the issue.</p>
  
  <p>The part of my code that detects mouseclicks uses a Windows function and aside from that I don't think my code is affected by which OS I'm using. I don't have any issues with click detection (because I solved them all already).</p>
  
  <p>A friend told me she would just use C++ strings and vectors to do the job, but I don't know them yet. I'll look them up but I'm hoping to find a solution without that if possible.</p>