When strtok is used and it doesn't find the delimiter when strtok is used the FIRST time, it should return a null. But this doesn't seems to be the behavior. Pl refer to this code -
char* szInputStr = "string to split up"; char *copy = NULL; /* Copy the szInputStr to Copy */ len = strlen(szInputStr); copy = (char *)malloc(len+1); strcpy(copy, szInputStr); /* Do strtok */ result = strtok(copy, "~"); if(result == NULL) printf("result is NULL \n"); else printf("result is NOT null \n");
Actually the value is same as the original string - "string to split up". The above code prints -
"result is NOT null"