Social Icons

Friday, 14 February 2014

Program to count number of words in a string

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

void main()
{
int i,words=1;
char str[100];
clrscr();
printf("\n Enter a string : ");
gets(str);
for(i=0;str[i]!='\0';++i)
if(str[i]==' ')
words++;

printf("\n Number of words are : %d",words);
getch();
}


                                                       Output

No comments:

Post a Comment