![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Print contents of a file in C
Here is an example to print contents of a file in C language,
Let’s say we have “new.txt” file with the following content.
0,hell!o 1,hello! 2,gfdtrhtrhrt 3,demo
Now, let us see the example.
Example
#include<stdio.h> #include<conio.h> void main() { FILE *f; char s; clrscr(); f=fopen("new.txt","r"); while((s=fgetc(f))!=EOF) { printf("%c",s); } fclose(f); getch(); }
Output
0,hell!o 1,hello! 2,gfdtrhtrhrt 3,demo
In the above program, we have a text file “new.txt”. A file pointer is used to open and read the file. It is displaying the content of file.
FILE *f; char s; clrscr(); f=fopen("new.txt","r"); while((s=fgetc(f))!=EOF) { printf("%c",s); }
Advertisements