File input/output program to access no. of character, spaces, tabs...

By using File Input/Output , we gonna count:-
No. of characters
No. of blanks
No. of tabs
No. of lines

So, here the code for the above.

/*Pre Processors */
#include<stdio.h>
#include<conio.h>

int main()     /*Main function*/
{
    FILE *fp;
    char ch;
    clrscr();
    int nol=0, not=0, nob, noc=0;
    fp=fopen("EMPLOYEE.TXT","r");
    while(1)
    {
        ch=fgetc(fp);
        if(ch==EOF)
        break;
        noc++;
        if(ch==' ')
        nob++;
        if(ch=='\n')
        nol++;
        if(ch=='\t')
        not++;
    }
    fclose(fp);
    printf("\nNumber of characters:- %d",noc);
    printf("\nNumber of blanks:- %d",nob);
    printf("\nNumber of tabs:- %d",not);
    printf("\nNumber of lines:- %d",nol);
    getch();
    return 0;
}



Comments