C Programming Code Examples C > File Operations Code Examples Reading a File in C programming language Reading a File in C programming language To read the file, we must open it first using any of the mode, for example if you only want to read the file then open it in "r" mode. Based on the mode selected during file opening, we are allowed to perform certain operations on the file. #include <stdio.h> int main() { /* Pointer to the file */ FILE *fp1; /* Character variable to read the content of file */ char c; /* Opening a file in r mode*/ fp1= fopen ("C:\\myfiles\\newfile.txt", "r"); /* Infinite loop -I have used break to come out of the loop*/ while(1) { c = fgetc(fp1); if(c==EOF) break; else printf("%c", c); } fclose(fp1); return 0; }