Sunday, September 11, 2011

count the no. of characters and no. of vowels in a file 2

// to count the no. of characters & no. of vowels in a file

#include<stdio.h>
#include<conio.h>
main()
{
    FILE *fp;
    char ch;
    int nov=0,noc=0;
    clrscr();
    fp=fopen("b.c","r");  // here 'b' is the name of the file to be opened.
    while(1)
    {
        ch=fgetc(fp);
        if(ch==EOF)
        break;
        noc++;
        if((ch=='a')||(ch=='e')||(ch=='i')||(ch=='o')||(ch=='u'))
            nov++;

           }
        fclose(fp);
        printf("\n number of characters=%d",noc);
        printf("\n number of vowels=%d",nov);
        getch();
        }

No comments:

Post a Comment

Popular 5 Posts Last 7 days