Sunday, February 8, 2015

counting vowles and consonents from a file

 /*This program counts  :
1. number of alphabets
2. number of vowles
3. number of consonents
4. number of lines

from a specified file.
*/

#include< stdio.h >
void main()
{
    FILE *fp1;
    char file1[50];
    unsigned char ch;
    long int noa,nov,nol,noc;
    char ch1;
    do
    {
        clrscr();
        printf("enter file name : ");
        gets(file1);
        fp1=fopen(file1,"rb");
        noa=nov=noc=nol=0;
        while(fscanf(fp1,"%c",&ch)>0)
        {
            if((ch>='A' && ch<='Z')||(ch>='a' && ch<='z'))
            {
                noa++;
                if(ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U' || ch=='a' || ch=='e' || ch=='i' ||ch=='o' || ch=='u' )
                    nov++;
            }
            else if(ch==13)
                nol++;
        }
        noc=noa-nov;
        fclose(fp1);
        printf("\nnumber of alphabets = %ld\nnumber of vowles = %ld\nnumber of consonents = %ld\nnumber of lines = %ld\n",noa,nov,noc,nol);
        printf("do you want to continue (y/n?) : ");
        ch1=getch();
    }while(ch1=='y'||ch1=='Y');
}

No comments:

Post a Comment