title: Parsing a C string and storing parts of the string in variables
body: <p>This post might be marked as a duplicate, but I did search online for this specific case and I couldn't find any examples similar to this. The following is a simplified version of my code.</p>
  <p>I have the following lines of data stored with a text file named <code>test.txt</code>:</p>
  <pre><code>12345|This is a sentence|More words here
  24792|This is another sentence|More words here again
  </code></pre>
  <p>The text in the <code>test.txt</code> file will always follow the format of <code>&lt;int&gt;|&lt;string&gt;|&lt;string&gt;</code></p>
  <p>I now want to store each of the sections separated by the delimiter <code>|</code> in a variable.</p>
  <p>The following is my attempt:</p>
  <pre><code>uint32_t num;
  char* str1, str2;
  
  // the data variable is a char pointer to a single line retrieved from test.txt
  sscanf(data, &quot;%d|%s|%s&quot;, &amp;num, str1, str2);
  </code></pre>
  <p>This code above would retrieve the correct value for <code>num</code> but would insert the first word from section two into <code>str1</code>, leaving the variable <code>str2</code> as null. To my understanding, this was the case because the <code>sscanf()</code> function stops when it hits a space.</p>
  <p>Is there an efficient way of storing each section into a variable?</p>