Wednesday, November 27, 2019

C Program for counting number of lines , number of spaces, number of digits in a given file


#include<stdio.h>
#include<ctype.h>
#include<conio.h>
void main(){
FILE *fp = fopen("bb.txt","r");
char c;
int cd=0,cs=0,cl=0;
while((c=getc(fp))!=EOF){

    if(isdigit(c)){
        cd=cd+1;
    }
    else if(isspace(c) && c!='\n'){
        cs=cs+1;
    }
    else if(c=='\n'){
        cl=cl+1;
    }
}
printf("number of digits %d \n",cd);
printf("number of spaces %d \n",cs);
printf("number of lines %d \n",cl);
fclose(fp);
getch();

}