C Source Codes List | Source Code Home
Program : Program to count no. of characters,no. of blanks,no. of words
/* Prg. to count no. of characters,no. of blanks,no. of words & no. of
lines in a multi line string */
#include
#include
void main()
{
char c,choice;
int nc=0,nb=0,nw=1,nl=1,count,i/*,flag=1*/;
clrscr();
scanf("%c",&choice);
/*while(flag)
{*/
printf("\t\t\tWELCOME TO THE PROGRAM SIR/MADAM\n\n\n");
printf("ENTER STRING:- ");
printf("\nString will be terminated when you press Ctrl-Z.");
printf("\nSTRING:- ");
while ((c=getchar())!=EOF)
{
switch(1)
{
case 1:
if (c==EOF||c==' '||c=='\n')
;
else
nc=nc+1;
case 2:
if (c==' ')
{
nc=nc+1;
nb=nb+1;
while((c=getchar())==' ')
{
nb=nb+1;
nc=nc+1;
}
if (c!=' ')
{
nc=nc+1;
nw=nw+1;
}
}
case 3:
if(c=='\n')
{
nc=nc+1;
nb=nb+1;
nw=nw+1;
nl=nl+1;
}
}
}
printf("\n\nno. of characters is %d",nc);
printf("\nno. of blanks is %d",nb);
printf("\nno. of words is %d",nw);
printf("\nno. of lines is %d",nl);
fflush(stdin);
printf ("\n\nDo you want to continue?(y/n):- ");
scanf("%c",&choice);
/* if (choice=='n')
flag=0;
}*/
printf("\n\n\n\n\n\t\t\tHAVE A NICE DAY! BYE.");
getch();
}
C Source Codes List | Source Code Home
|
|