tof函数c语言 c语言fcntl函数( 二 )


gTokens[i].stat=0;
}
printf( "%s\n\nTokens:\n", string );
/* Establish string and get the first token: */
token = strtok( string, seps );
while( token != NULL )
{
// 统计信息
{
int i;
for (i=0;i1024;i++)
{
if ( strlen(gTokens[i].token)==0)
{
strcpy(gTokens[i].token, token);
gTokens[i].stat++;
break;
}
else
{
if ( strcmp(gTokens[i].token,token)==0)
{
gTokens[i].stat++;
break;
}
}
}
}
/* Get next token: */
token = strtok( NULL, seps );
}
for (i=0;i1024;i++)
{
if (strlen(gTokens[i].token)0)
{
printf("token=%s, stat=%d\n", gTokens[i].token, gTokens[i].stat);
}
}
}
输出结果:
moose@iBookG4:~/Projects/svn_repo/trunk/data_struct/glibc$ ./a.out
DESCRIPTION
For strtok(): [CX] [Option Start] The functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements described here and the ISO C standard is unintentional. This volume of IEEE Std 1003.1-2001 defers to the ISO C standard. [Option End]
A sequence of calls to strtok() breaks the string pointed to by s1 into a sequence of tokens, each of which is delimited by a byte from the string pointed to by s2. The first call in the sequence has s1 as its first argument, and is followed by calls with a null pointer as their first argument. The separator string pointed to by s2 may be different from call to call.
The first call in the sequence searches the string pointed to by s1 for the first byte that is not contained in the current separator string pointed to by s2. If no such byte is found, then there are no tokens in the string pointed to by s1 and strtok() shall return a null pointer. If such a byte is found, it is the start of the first token.
The strtok() function then searches from there for a byte that is contained in the current separator string. If no such byte is found, the current token extends to the end of the string pointed to by s1, and subsequent searches for a token shall return a null pointer. If such a byte is found, it is overwritten by a null byte, which terminates the current token. The strtok() function saves a pointer to the following byte, from which the next search for a token shall start.
Each subsequent call, with a null pointer as the value of the first argument, starts searching from the saved pointer and behaves as described above.
Tokens:
token=DESCRIPTION, stat=1
token=For, stat=1
token=strtok(), stat=5
token=CX, stat=1
token=Option, stat=2
token=Start, stat=1
token=The, stat=6
token=functionality, stat=1
token=described, stat=3
token=on, stat=1
token=this, stat=1
token=reference, stat=1
token=page, stat=1
token=is, stat=12
token=aligned, stat=1
token=with, stat=3
token=the, stat=24
token=ISO, stat=3
token=C, stat=3
token=standard, stat=3
token=Any, stat=1
token=conflict, stat=1
token=between, stat=1
token=requirements, stat=1
token=here, stat=1
token=and, stat=5
token=unintentional, stat=1
token=This, stat=1
token=volume, stat=1
token=of, stat=7
token=IEEE, stat=1
token=Std, stat=1
token=1003, stat=1
token=1-2001, stat=1
token=defers, stat=1
token=to, stat=12
token=End, stat=1
token=A, stat=1
token=sequence, stat=4
token=calls, stat=2
token=breaks, stat=1
token=string, stat=8
token=pointed, stat=7
token=by, stat=10
token=s1, stat=5
token=into, stat=1
token=a, stat=13
token=tokens, stat=2
token=each, stat=1
token=which, stat=3
token=delimited, stat=1
token=byte, stat=9
token=from, stat=5
token=s2, stat=3

推荐阅读