Monday 5 October 2015

Write a program to count total words in text.

  
   
#include<stdio.h>
#include<string.h>
#include<ctype.h>
//#include<conio.h>
void main() {
    char sen[100];
    int i, count = 1;
    //clrscr();
    printf("Enter a Sentence : \n");
    gets(sen);
    for (i = 0; i < strlen(sen); i++) {
        if (isspace(sen[i])) {
            count++;
        }
    }
    printf("Number of words in the sentence = %d", count);
    printf("\n");
    //getch();
}
Note: Remove the comment line when you are use Turbo C IDE for run your program.

No comments:

Post a Comment