#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void divide_Tokens(char Str[])
{
char *Ptr;
int count = 1;
char *tokens;
int i = 0;
Ptr = strtok(Str," ");
while ( Ptr )
{
Ptr = strtok(NULL," ");
if ( Ptr )
{
count++;
}
}
tokens = (char *)malloc(count * sizeof(char));
Ptr = strtok(Str," ");
for ( i = 0 ; i < count ; i++ )
{
*(tokens + i) = Ptr;
if ( Ptr )
{
Ptr = strtok(NULL," ");
}
}
for ( i = 0 ; i < count ; i++ )
{
printf("%s",*(tokens + i));
}
}
int main()
{
char A[] = "AA BB CCC DDD EE FF GGGG";
divide_Tokens(A);
return 0;
}
请问为什么得到7个(NULL)
而不是AABB…
是赋值字符串时错了吗?