Friday, May 30, 2014

WRITE A PROGRAMME TO COUNT THE NO OF WORDS IN A STRING

#include<conio.h>
#include<stdio.h>
void main()
{
char s1[50];
int i=0,j,c=0;
clrscr();
printf("enter the string\n");
gets(s1);
while(s1[i])
{
if(s1[i]==32)
 {
  c++;
if(s1[i+1]==32)
{
 j=i+1;
 while(s1[j]==32)
 {
    j++;
    continue;
 }
 i=j;
}
  }
i++;
}
printf("no of words in %s are %d",s1,++c);
getch();
}

No comments:

Post a Comment