Write a C program to display the contents of a file.
Algorithm:
1. Start
2. Read file name
3. Open file in reading mode
4. Repeat until end of the file and print the contents if the file
5. Close the file
6. Stop
Program Code:
#include<stdio.h>
void main()
{
FILE *fp;
char ch;
fp=fopen("file.txt","r");
if(fp==NULL)
{
printf("file opening problem");
return;
}
while(!feof(fp))
{
ch=fgetc(fp);
printf("%c",ch);
}
fclose(fp);
}
Thanks
Mukesh Rajput
Post A Comment:
0 comments: