title: Splitting a white-spaced string using sscanf()
body: <p>I'm trying to split a long string with white-spaces, using <code>sscanf()</code>.</p>
  
  <p>For example: I need to split this</p>
  
  <pre><code>We're a happy family
  </code></pre>
  
  <p>into</p>
  
  <pre><code>We're
  a
  happy
  family
  </code></pre>
  
  <p>I tried the following approach</p>
  
  <pre><code>char X[10000];
  fgets(X, sizeof(X) - 1, stdin); // Reads the long string
  if(X[strlen(X) - 1] == '\n') X[strlen(X) - 1] = '\0'; // Remove trailing newline
  char token[1000];
  while(sscanf(X, "%s", token) != EOF) {
      printf("%s | %s\n", token, X);
  }
  </code></pre>
  
  <p>The previous code goes into an infinite loop outputting <code>We're | We're a happy family</code> </p>
  
  <p>I tried to replace <code>sscanf()</code> with C++ <code>istringstream</code>, it worked fine.</p>
  
  <p>What makes X keep it's value? Shouldn't it be removed from buffer like normal stream?</p>