Write a Program to get char and line count in File

//File char count and line count

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
 FILE *fp;
 char ch;
 int line=1,c=1;
 clrscr();
 fp=fopen("C:\\abc.txt","r");
  if(fp==NULL)
   {
    puts("File not found");
    exit(0);
   }
 while(1)
  {
   ch=fgetc(fp);
   if(ch==EOF)
    break;
    c++;
    if(ch=='\n')
      line++;

     }
       fclose(fp);
        printf("Total characters =%d\n",c);
        printf("line count =%d",line);


getch();
}

No comments:

Post a Comment

Related Post

Array:
String functions:
General (Loops-for/while)
Write a Program to print reverse of a given number Write a Program to print Product of Digits (eg. 212=2*1*2=4) of a given number Write a C++ Program to Convert Binary into Decimal Number