Program to read String from a file


#include<stdio.h>
#include<conio.h>
main()
{
 FILE *fp;
 char s[25];
 clrscr();

 fp=fopen("Filename.extension","r");

 if(fp==NULL)
 {
 printf("cannot open the file");
 getch();
 exit(0);
 }

 while(fgets(s,sizeof(s),fp)!=NULL)
 printf("%s",s);

 fclose(fp);
 getch();
}

0 comments:

Post a Comment