Skip to main content

C program to read strings from existing file using fgets()


#include<stdio.h>
#include<conio.h>
 void main()
{ char s[50];
  int len=0;
  FILE * pk=fopen("keviv.txt","r");
  clrscr();
  if(pk==NULL)
  { printf("\n FILE DOES NOT EXIST ");
    getch();
    exit(0);
  }
  while(1)
  { len=fgets(s,49,pk);
    if(len==NULL)
      break;
    puts(s);
  }
  getch();
  fclose(pk);
  }

Comments