Monday, November 29, 2010

//counting no of words

#include
#include
void main()
{
int i,words=0;
char text[100];
printf("enter the text and give '$' at end");
for(i=0;(text[i]=getchar())!='$';i++)
;
text[i]='\0';
for(i=0;text[i]!='\0';i++)
{
if((text[i]!=' '&& text[i+1]==' ')
(text[i]!='\t'&&text[i+1]=='\t')
(text[i]!='\n'&&text[i+1]=='\n'))
words++;
}
printf("%d words in a given string",words);
getch();
}

No comments:

Post a Comment