Answers for "count words in string c"

C
1

count number of words in a string in c

/*
 * C Program to Count Number of Words in a given Text Or Sentence
 */
#include <stdio.h>
#include <string.h>
 
void main()
{
    char s[200];
    int count = 0, i;
 
    printf("Enter the string:n");
    scanf("%[^n]s", s);
    for (i = 0;s[i] != '';i++)
    {
        if (s[i] == ' ' && s[i+1] != ' ')
            count++;    
    }
    printf("Number of words in given string are: %dn", count + 1);
}
Posted by: Guest on June-21-2021

Code answers related to "C"

Browse Popular Code Answers by Language