google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.: Write a C program to count number of words in a given text or sentence.

Tuesday, April 7, 2020

Write a C program to count number of words in a given text or sentence.

Write a C program to count number of words in a given text or sentence.

#include
#include

void main()
{
    char s[200];
    int count = 0, i;

    printf("Enter the string:\n");
    scanf("%[^\n]s", s);
    for (i = 0;s[i] != '\0';i++)
    {
        if (s[i] == ' ' && s[i+1] != ' ')
            count++;    
    }
    printf("Number of words in given string are: %d\n", count + 1);
}





Output:

Enter the string:
welcome to vijaymarwaha.blogspot.com blog
Number of words in given string are: 4

1 comment:

शिव भोलेनाथ स्तुति

 जय शिवशंकर, जय गंगाधर, करुणा-कर करतार हरे,   जय कैलाशी, जय अविनाशी, सुखराशि, सुख-सार हरे जय शशि-शेखर, जय डमरू-धर जय-जय प्रेमागार हरे,   जय ...