How to read a file and display it in c
/*Program to read a file and display it*/
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
int ch;
char fname[32];
clrscr();
//Accept file name
printf("Enter File name:\n");
scanf("%s",fname);
//open file
fp=fopen(fname,"r");
if(fp==NULL)
{
printf("ERROR:File cannot open");
getch();
return;
}
//display file till end
while((ch=fgetc(fp))!=EOF)
putchar(ch);
fclose(fp);
getch();
}
0 comments: