This C program counts number of words and characters in a string.
Example :
Example :
- " hello world " is a string.
- No of word in a string : 2
- No of character in a string :10
Program :
#include<stdio.h> #include<conio.h> #include<string.h> void main() { char ch; do{ char a[20]; int i,w=1,c=0; clrscr(); printf("Enter a string:"); gets(a); strlwr(a); for(i=0;a[i]!=NULL;i++) { if(a[i]==' '&& a[i+1]!='.') w++; if(a[i]>='a' && a[i]<='z') c++; } printf(" No of Word in a String : <%d>",w); // Check next character [i+1] printf(" No of Character in a String : <%d>",c); printf("\n Continue(y/n):"); ch=getch(); }while(ch=='y'||ch=='Y'); }
If you have any Further Information and Quires about this Article don't hesitate to comment in comment box below.
AND
If you like this article , like our Facebook like page and click +1 to support 123techguide
|