10 Mar 2013

Words Count in String

/*

Program to count the no. of words in a string....

*/

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char a[50];
int i,j,c=1;
cout<<"Enter the string:";
gets(a);
for(i=0;a[i]!='\0';i++)
{
if(a[i]==' ')
c++;
}
if((a[i]=='\0') && (a[i-1]==' '))
c--;
cout<<"The no. of words are:"<<c;
getch();
}

Categories: , , ,

Related Posts:

  • Words Count in String /* Program to count the no. of words in a string.... */ #include<iostream.h>#include<conio.h>#include<stdio.h>void main(){clrscr();char a[50];int i,j,c=1;cout<<"Enter the string:";gets(a);for(i=0;… Read More

0 comments:

Post a Comment

Copyright © 2025 UPgradeCODING | Powered by Blogger