#include <stdio.h>
int main()
{
char s[100]=""; //The way you get the string decides if you can choose traversal operators.
// while you have known that its end is '.', and you should choose to judge the string's element one by one.
gets(s);
int i,j,k,count=0;
for(k=0;k<100;)
{
for(i=k;i<100;i++)
{
if(s[i]==' '||s[i]=='.')
break;
count++;
}
if(count!=0&&s[i]!='.')
{
printf("%d ",count);
count=0;
}
else
{
printf("%d",count);
count=0;
}
if(s[i]=='.') break;
k=++i;
}
return 0;
}
And the follwing one is the right edition. "Scanf " it noe by one.
#include <stdio.h>
int main()
{
char s;
int i,count;
do
{
scanf("%c",&s);
if(s=='.')
{
if(i)
printf("%d",i);
}
if(s==' ')
{
if(i)
{
printf("%d ",i);
i=0;
}
}
else
++i;
}while(s!='.');
return 0;
}