printing token returned from strtok or strtok_r crashes : <p>I have tried a simple program on my linux machine which tokenize a string using delimiter (",") and prints all the token values. But its crashing on very first statement which tries to print the token value.</p>

<p>Here is my program</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

void main()
{
    char *query = "1,2,3,4,5";
    char *token = strtok(query, ",");
    while(token)
    {
        printf("Token: %s \n", token);
        token = strtok(NULL, ",");
    }
}
</code></pre>

<p>output:</p>

<pre><code>Segmentation fault (core dumped)
</code></pre>

<p>BT in GDB:</p>

<pre><code> (gdb) r
 Starting program: /home/harish/samples/a.out

 Program received signal SIGSEGV, Segmentation fault.
 strtok () at ../sysdeps/x86_64/strtok.S:186
 186     ../sysdeps/x86_64/strtok.S: No such file or directory.
</code></pre>

<p>Build System:</p>

<pre><code>64 bit Ubuntu, gcc 4.8.4 version.
</code></pre>
