title: How to read word for word that are only separated by a ":" from the buffer?
body: <p>I am making a language translator, and want to read from the buffer word by word and store them in a key-value struct.</p>
  
  <p>The buffer contains such a file: </p>
  
  <pre><code>hola:hello
  que:what
  </code></pre>
  
  <p>and so on. I already tried everything and I keep errors such as segmentation fault: 11 or just reading the same line again and again. </p>
  
  <pre><code>struct key_value{
  char *key;
  char *value;
  };
  </code></pre>
  
  <p>...</p>
  
  <pre><code>struct key_value *kv = malloc(sizeof(struct key_value) * count);
  char k[20]; //key
  char v[20]; //value
  int x = 0;
  for(i = 0; i &lt; numbytes; i++){
      sscanf(buffer,"%21[^:]:%21[^\n]\n",k,v);
      (kv + i)-&gt;key = k;
      (kv + i)-&gt;value = v;
  }
  
  for(i = 0; i &lt; count; i++){
      printf("key:  %s, value:  %s\n",(kv + i)-&gt;key,(kv + i)-&gt;value);
  }
  
  free(buffer);
  free(kv);
  </code></pre>
  
  <p>I expect the output to be <code>key: hola, value: hello key: que, value: what</code>,
  but the actual output is just <code>key: hola, value: hello</code> again and again.</p>
  
  <p>Which is the right way to do it?</p>