strtok函数实现一直出现写入冲突问题
#include <stdlib.h>
#include <stdio.h>
char* strtok1(char *str, const char *delim)
{
static char *sstr ;
static char *s1, *s2;
if(*str == NULL)
str = sstr;
if(*str == NULL)
return NULL;
s1 = str;
while(*str!= '\0')
{
if(*str == *delim)
{
*str = '\0';
sstr = str + 1;
break;
}
str++;
}
return s1;
}
int main()
{
char *str ="asdf,dsgfsd,dsfhs";
char *str1 = strtok1(str, ",");
char* str2 = strtok1(NULL, ",");
}
if (/***/str == NULL) str = sstr;
if (/***/str == NULL) return NULL;