#include
int split(char*,char**);
int main(void)
{
char str[200], *pStr[101];
int i=0, count;
int n = 0;
printf("Please input a string: ");
gets(str);
count = split(str, pStr);
printf("\n%d Words: ", count);
for (i=0; i
printf("%s-", pStr[i]);
}
putchar('\n');
return 0;
}
int split(char* str,char** pStr)
{
int i;
int j;
int count;
if(*str=='\0')
{
for(i=0;i<101;i++)
*(pStr+i) = 0;
return 0;
}
else if(*str!=' ')
{
*pStr = str;
j=1;
count = 1;
}
else
{
j=0;
count = 0;
}
i = 0;
while(*(str+i+1)!='\0')
{
if(*(str+i)==' '&& *(str+i+1)!=' ')
{
count++;
*(pStr+j) = str+i+1;
j++;
}
i++;
}
i = 0;
while(*(str+i+1)!='\0')
{
if(*(str+i)!=' ' && *(str+i+1)==' ')
*(str+i+1) = '\0';
i++;
}
return count;
}