Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to count word from user entered text or sentence

Posted By: Carole Walker     Category: C Programming     Views: 15327

Program to count word from user entered text or sentence

Code for Program to count word from user entered text or sentence in C Programming

#include <stdio.h>
#include <conio.h>
    void main()
    {
        char a[100],b[10],t[20];
        int i=0,n=0,w=1;
        clrscr();
        printf("\n Enter The String : ");
        scanf("%[^\n]",a);
        printf("\n Enter The Word Which Count : ");
        scanf("%s",b);
        while(a[i]!='\0')
        {
            t[n]=a[i];
            if(a[i]==' ')
            {
                t[n]='\0';
                //printf("\n %s",t);
                n=-1;
             if(strcmp(t,b)==0)
             w++;
             }
            i++;
            n++;
        }
        printf("\n %s comes %d times ",b,w-1);
        getch();
    }

/*
******
OUTPUT
******

Enter The String : MICHEL IS GOOD IN C C IS GOOD LANGUAGE

Enter The Word Which Count : GOOD

GOOD comes 2 times
*/
  
Share: 


Didn't find what you were looking for? Find more on Program to count word from user entered text or sentence Or get search suggestion and latest updates.

Carole Walker
Carole Walker author of Program to count word from user entered text or sentence is from St Louis, United States.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!