Monday, December 13, 2010

Program to calculate the total number of words in the given text

#include<stdio.h>
#include<string.h>
int main()
{
    char a[20];
    int i,n,count=0;
    printf("Enter the text:");
    gets(a);
    n=strlen(a);

    for(i=0;i<=n;i++)
    {
        if(a[i]==' '||a[i]=='\0')
        count++;
    }
    printf("\nTotal number of words in the string is %d.",count);
    return 0;
}

No comments:

Post a Comment