C program that counts the number of words in a given string.


///Word count from a given string in c
/*
Alamgir Hossain, CSE-14, JUST
*/
#include <stdio.h>
#include <string.h>

int main()
{
    char s[1000];
    int c = 0, i;

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


    printf("\nThank You!!!!!!\n");
    return 0;
}

No comments:

Post a Comment