title: strsep() usage and its alternative
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  int main() {
  
  char *slogan = "together{kaliya} [namak]";
  char *slow_gun = strdup(slogan);
  
  char *token = strsep(&amp;slow_gun, "{");
  
  printf ("\n slow_gun: %s\n token: %s\n", slow_gun, token);
  
  return 0;
  }
  </code></pre>
  
  <p>when I execute it:</p>
  
  <pre><code>$ cc -o try try_strsep.c
  $ ./try
  
   slow_gun: kaliya} [namak]
   token: together  
  </code></pre>
  
  <p>But when, I change the char *slogan to:</p>
  
  <pre><code>char *slogan = "kalia} [namak]";
  </code></pre>
  
  <p>and execute the same program:</p>
  
  <pre><code>$ vi try_strsep.c 
  $ cc -o try try_strsep.c
  $ ./try
  
   slow_gun: (null)
   token: kalia} [namak]
  </code></pre>
  
  <p>My <strong>Question</strong> is, so when I use strsep() and input string does not have the pattern I am looking for, the return of strsep() is <strong>wrong</strong>. The only way I can validate whether strsep() could not find the pattern is to check <code>if (slow_gun == NUll)</code>.</p>
  
  <p>If I have <code>char *slogan = "together{"</code> then <code>strsep</code> would successfully return <code>token</code> but returns <code>slow_gun</code> to blank (not <code>null</code>)</p>
  
  <pre><code>$ cc -o try try_strsep.c
  $ ./try
  
   slow_gun: 
   token: together
  </code></pre>
  
  <p>Is there a way I could avoid this IF check and rely on the function to return me the substr and if its not there, return <code>NULL</code>?</p>