Contact Learn C
Copy Program Share Program

Program 202:Reading a File and Printing on console

Program 202:
 
#include<stdio.h>
#include<stdlib.h>
 main ()
 {
    FILE *file;
    char c;
    file=fopen("file123.txt","r");
    while(1)
    {
     if(file==NULL)
     {
      printf("File Not Found\n");
      exit(0);
     }
     else
     {
      c=fgetc(file);
      if(c==EOF)
      {
       break;
      }
      printf("%c",c);
     }
    }
    fclose(file);
 }
Explanation:

//Coming Soon...

Output:

Store both text file and program in same folder.Here I named text file as file123.txt










 

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide