title: C - Strtok() , split the string on '\n' but keep the delimiter
body: <p>I have the following problem with my C program. Part of it's functionality is to read some text and split it into sentences then write those sentences in a file.</p>
  
  <p>I used Strtok() to split the chunk of text in sentences (a sentence ends when \n occurs) however when there is a sentence that just contains the \n character in a chunk of text like : </p>
  
  <p>//////////////////////////////</p>
  
  <p>Hello, this is some sample text<br>
     This is the second sentence</p>
  
  <p>The sentence above is just a new line<br>
     This is the last sentence.</p>
  
  <p>/////////////////////////////</p>
  
  <p>The output of the file is as follows :</p>
  
  <p>0 Hello, this is some sample text<br>
     1 This is the second sentence<br>
     2 The sentence above is just a new line<br>
     3 This is the last sentence.</p>
  
  <p>////////////////////////////////////////////////////</p>
  
  <p>While it should be :</p>
  
  <p>0 Hello, this is some sample text<br>
   1 This is the second sentence<br>
   2<br>
   3 The sentence above is just \n<br>
   4 This is the last sentence.</p>
  
  <p>////////////////////////////////////</p>
  
  <p>The file holding the strings should function as a log file that's why I have to split the chunk of text in sentences split at \n and before writing each sentence into the file have an integer in front.</p>
  
  <p>This is the code related to this functionality :</p>
  
  <pre><code>int counter = 0; // Used for counting
  const char s[2] = "\n"; // Used for tokenization
  
  // ............
  
  char *token;
        token = strtok(input,s);
        while(token != NULL){
          fprintf(logs, "%d ", counter);
          fprintf(logs, "%s\n" , token); // Add the new line character here since it is removed from the tokenization process
          counter++;
          token = strtok(NULL, s);
        }
  
  // .........
  </code></pre>
  
  <p>Is there a way to have a special case for when an "empty sentence" (a sentence that is just a \n character) to handle it properly?</p>
  
  <p>Perhaps another function would work instead of strtok()?</p>