Write a C program to display the contents of a file.

Algorithm:

Step 1: Start
Step 2: open a empty file in write mode.
Step 3: if it is not end of file
Step 4: write data into that file.
Step 5: close the write mode operation
Step 6: now open that file in read mode.
Step 7: the contents of the file will be displayed
Step 8: Stop

Program:

#include<stdio.h>
#include<conio.h>
FILE *fp1,*fp2;
char c;
void main()
{
 clrscr();
 printf("enter the text\n");
 fp1 = fopen("abc.txt", "w");
 while((c = getchar()) != EOF)
  putc(c, fp1);
 fclose(fp1);
 fp1 = fopen("abc.txt","r");
 fp2=fopen("xyz.txt","w");
 while(!feof(fp1))
 {
  c = getc(fp1);
  putc(c,fp2);
 }
 fclose(fp1);
 fclose(fp2);
 printf("the copied data is \n");
 fp2 = fopen("xyz.txt", "r");
 while(!feof(fp2))
 {
  c = getc(fp2);
  printf("%c", c);
 }
 getch();
}

Input & Output:

enter the text
engineering students are very good.
^Z
the copied data is
engineering students are very good.