Ticker

6/recent/ticker-posts

C Language (File reading in C)

FILE READING IN C

File reading is used to fetch the data from an already existing file and print the file''s data in the console window (output window)





PROGRAM TO READ/FETCH DATA FROM FILE
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();

// Create FILE class pointer 
FILE *fp=fopen("test.txt","r");
int ch=getc(fp);

// Loop to read data from file
while(ch != EOF)
{
putchar(ch); // Print data on output (console) window
ch = getc(fp); //Read data by ch variable
}
getch();
}


----------------------------

         OUTPUT 
----------------------------
Welcome in my first file

















Post a Comment

0 Comments