Sunday 22 July 2012

How to read a file and display it in c

 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();
}

Share This
Previous Post
Next Post

FYJC XI standard online admisson Process and declaraton of Merit list . Cut off List For prevous year also . 10 Th Results onlne declaraton Maharashtra Region .

0 comments: