/* assuming that word separators are , . ' '(space) considering that , . ' '(space) are not characters */
#include < stdio.h >
#include < conio.h >
void main()
{
int flag=0;
char c;
int no_words=0,no_char=0;
printf("Enter sentence...\n");
while((c=getchar())!='\n')
{
no_char++;
if(c==' '||c=='.'||c==',')
{
if(flag==1)
{
}
else
{
no_words++;
flag=1;
}
no_char--;;
}
else
{
flag=0;
}
}
printf("Number of words are %d",no_words+1);
printf("Number of characters are %d",no_char);
getch();
}
Thursday, September 4, 2008
C program to count no. of characters and words
Posted by Nanya at 7:37 AM
Subscribe to:
Post Comments (Atom)
2 comments:
Yet to find a female so engrossed wid C Codes;) kp writin....
wow great work.. almost all the codes do work after all!
Post a Comment