Number of line breaks and space in a file

File Handling in C
#include <stdio.h>
int main(void){
FILE *fpt; // file pointer
char str;
int i,lb=0,sp=0;
fpt=fopen("data2.txt","r"); // file already exit for reading
if(fpt==NULL)
    printf("Can't open file ");
else {
 while(str != EOF){
       str=getc(fpt);
       if(str=='\n'){
       	lb=lb+1;
	   }
	  if(str==' '){
       	sp=sp+1;
	   }       
}
    fclose(fpt);
}
printf("No of line breaks : %d \n",lb);
printf("No of space : %d \n",sp);
return 0;
}
data2.txt file is here
welcome to plus2net
 Next Line 
Output is here
No of line breaks : 1
No of space : 6
File Handling in C

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer