Basic Programs
If Else based Programs
Loop Based Programs
Array Based Programs
String Programs
Function Programs
Pointers Programs
Structure & File Handling Programs
Data Structure Programs
Structure and File Handling programs
Read from file using C
#include <stdio.h> #include <conio.h> void main() { int num; FILE *fp; char ch;
int noc=0;
fp = fopen("test.c","r");
// Full path to open a file as below
//fp = fopen("D:\\TestFolder\\test.txt","r");
if(fp == NULL) { printf("File not exist"); exit(1); } else { ch=fgetc(fp); while(ch!=EOF) { printf("%c", ch); ch=fgetc(fp);
noc++; }
printf("\n no of characters in the file=%d",noc);
} }// end of main
Output of the above program is as following.
Video/ C Introduction
Watch video in full size