Using the code below, the program crashes. This is the code I copied from this source and did not change it at all, but strtok seems to cause the program to crash.
#include <string.h>
#include <stdio.h>
int main()
{
char str[80] = "This is - www.tutorialspoint.com - website";
const char s[2] = "-";
char *token;
token = strtok(str, s);
while( token != NULL )
{
printf( " %s\n", token );
token = strtok(NULL, s);
}
return(0);
}
I can not find the reason for this. I tried looking for the source of the strtok function and came across this :
char * __cdecl strtok(char *s1, const char *delimit)
{
static char *lastToken = NULL;
char *tmp;
if ( s1 == NULL ) {
s1 = lastToken;
if (s1 == NULL)
return NULL;
} else {
s1 += strspn(s1, delimit);
}
tmp = strpbrk(s1, delimit);
if (tmp) {
*tmp = '\0';
lastToken = tmp + 1;
} else {
lastToken = NULL;
}
return s1;
}
, , , , strpbrk , ( printf ), \0 (, ).
, , , ?
.