-->

Facebook

Jasper Roberts - Blog

Saturday, April 4, 2015

Write a C program to count total words in text.

PRACTICAL-SET-5
1.   Write a progratcount total words in text.

#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
    char s1[50];
    int i, count = 0;
    clrscr();

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

}

OUTPUT:
c programs
string length

No comments:

Post a Comment