Write a program to display contents of file “a.txt” on the screen.

C File =>

// Write a program to display contents of file “a.txt” on the screen. 


 #include<stdio.h>
#include<stdlib.h>
int main() {
   FILE *fp;
   char ch;
   fp=fopen("a.txt","r");
   if(!fp)
     printf("\n Error in reading file");
   else
  {
     while((ch=fgetc(fp))!=EOF)
        printf("%c",ch);
   }
  return 0;
}


Note :  First create a.txt file and then write above c file

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.