Search This Blog

Translate

c file handling programs to count number of lines

c file handling programs to count number of lines


#include
#include
#include
void main()
{
  FILE *source,*dest;
  char ch;
  int cnt=0;
  clrscr();
  source=fopen("D:one.txt","r");
  if(source==NULL)
  {
   printf("\n Source file not found");
   exit(1);
  }
  while((ch=fgetc(source))!=EOF)
  {  if(ch=='\n')
     cnt++;
  }
  printf("%d\t lines",cnt);
  fclose(source);
 getch();
}

C Program example List

Google+ Badge