From C #, Java to C, I feel like I have returned to the primitive society from a public-productive society, so I am very angry !!!
Function Name: strtok
Function: searches for words separated by the delimiters specified in the second string.
Usage: Char * Strtok ( Char * Str1, Char * Str2 );
Program example:
# Include < String . H >
# Include < Stdio. h >
Int Main ( Void )
{
Char Input [ 16 ] = " ABC, d " ;
Char * P;
/**/ /*Strtok places a null Terminator
In front of the token, if found*/
P = Strtok (input, " , " );
If (P) printf ( " % S \ n " , P );
/**/ /*A second call to strtok using a null
As the first parameter returns a pointer
To the character following the token*/
P = Strtok (null, " , " );
If (P) printf ( " % S \ n " , P );
Return 0 ;
}
The following is a disgusting strtok function used to separate strings.
Its second parameter cannot be a char * variable. It is OK if it is a char [] variable.
Fuck!
I did n tests to find this problem, which caused me to debug UNIX Network Programming jobs for a long time.
This function is really strange to call.
The parameter needs to be set for the first time. The second parameter can be null.
Then the function can actually split the characters set for the first time.
I'm speechless
This design is too unfriendly.
Let's take this function seriously. If someone who is as depressed as me finds this functionArticle, Maybe less detours
Two parameters must be set for the first call of the function. The strtok (STR, ",") STR must be separated by the string ",".
Returns the first, previous, or preceding string in the string.ProgramFirst output ABC
The second call to this function strtok (null, "."), the first parameter is set to null, and the second parameter is based on segmentation.
The result returns the Split Based on the subsequent string, that is, the above program outputs d