Search This Blog

Translate

c file handling programs to count number of lines from text file using CMD

 c file handling programs to count number of lines from text file using CMD


#include
#include
#include
void main(int argc,char *argv[])
{
  FILE *source;
  char ch;
  int cnt=1;

  clrscr();
  if(argc!=2)
  {
   printf("Wrong argument");
   exit(1);
  }
  source=fopen(argv[1],"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