/*    WRITE A C PROGRAM TO COUNT THE NUMBER OF CHARACTERS, 
    WORDS AND LINES IN A TEXT. 
*/
#include<stdio.h>
#include<conio.h>
#define ROW 50
#define COL 100
#define CTRL_Q 17
void main()
{
            char str[ROW][COL];
            int ch=0,words=0,lines=0,i=0,j;
            clrscr();
            printf("Enter Text and press CTRL+q to end text\n\n");
            while(i < ROW)
            {
                        gets(str[i]);
                        if(str[i][0]==CTRL_Q)
                                    break;
                        i++;
            }
            lines=i;
            for(i=0;i<lines;i++)
            {
                        for(j=0;j<strlen(str[i]);j++)
                        {
                                    if(str[i][j]==' ')
                                                words++;
                                    else
                                                ch++;
                        }
                        words++;
            }
            printf("\nThe Number of CHARACTERS is : %d", ch);
            printf("\nThe Number of WORDS is      : %d", words);
            printf("\nThe Number of LINES is      : %d", lines);
            getch();
}
/*
            =====OUT PUT=====
            Enter Text and press CTRL+q to end text
            ALL THE PROGRAMS ARE DONE BY BHARATH AND
            KAUNDINYA. BHARATH DID MAXIMUM NUMBER OF
            PROGRAMS AND KAUNDINYA HELPED HIM.
            THEIR E-ids are
            bha_pal@indiatimes.com
            kaun_ignou@yahoo.com
            ^Q
            The Number of CHARACTERS is : 153
            The Number of WORDS is      : 27
            The Number of LINES is      : 7
*/
 
No comments:
Post a Comment