Monday, July 22, 2013

Program to read a string and to count the number of words

#include<iostream.h>
#include<stdio.h>
int main()
{
clrscr();
char str[80];
int i;
int wordcount=0;
puts("Enter a string upto 80 characters : ");
gets(str);
for(i=0;str[i]!='\0';i++)
{
    if(str[i]==' ')
    wordcount++;
}
cout<<"The number of words are "<<wordcount<<"\n";
return0;
}

No comments:

Post a Comment