Program to read text from a file and display it on screen
We will write a program in C that will read a text file character by character and displays it on the screen. In order to achieve it, we will use fopen
function that will open the file from the disk. We will also use fgetc
function which will read the file character by character and then display the content of the string character by character.
#include<stdio.h> #include<conio.h> void main() { FILE *fp; char ch; fp = fopen("file1.C","r"); while(1) { ch = fgetc(fp); if (ch == EOF) break; printf("%c", ch); } getch(); fclose(fp); }
C Programming is brought you by LearnCOnline.com
1 Response
[…] Program to read text from a file and display it on screen […]