Can someone point out the mistake . I thought this was the crrect way of using strtok. But its running into seg fault
Code:#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { char * tch=strtok("aaaa its okay"," "); while (tch != NULL) { printf("%s\n",tch); tch = strtok (NULL, " "); } }
gdb output
gdb) run
Starting program: /var/www/YB_EmailAlerts/test/a.out
Program received signal SIGSEGV, Segmentation fault.
0xb7ebd0c5 in strtok () from /lib/i386-linux-gnu/libc.so.6
(gdb) up
#1 0x08048432 in main () at a.c:9
9 char * tch=strtok("aaaa its okay"," ");