View Code of Problem 58

#include<stdio.h>
#include<string.h>
int main()
{
    char str[1000];
    int count=0,i,len;
    gets(str);
    len=strlen(str);
    if(len==1)
        count=1;
    else
    {
        for(i=1;i<len;i++)
        {
            if(str[i]==' '&&str[i-1]!=' ')
                count++;
        }
        if(str[len-1]==' ') 
            count--;
		count+=1;
    }
    printf("%d\n",count);
    return 0;
}

Double click to view unformatted code.


Back to problem 58