Write a program to read and print data stored in a file input.txt.

This answer is restricted. Please login to view the answer of this question.

Login Now
#include <stdio.h>

int main()
{
   char ch;
   FILE *fp;

   fp = fopen("input.txt", "r");

   if (fp == NULL)
   {
      printf("Error while opening the file.\n");
      exit(0);
   }

   printf("The contents of %s file are:\n", file_name);

   while((ch = fgetc(fp)) != EOF)
      printf("%c", ch);

   fclose(fp);
   return 0;
}

 

If you found any type of error on the answer then please mention on the comment or report an answer or submit your new answer.
Leave your Answer:

Click here to submit your answer.

Discussion
0 Comments
  Loading . . .