
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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); }
- Related Questions & Answers
- How to print out the contents of a vector in C++?
- Merge contents of two files into a third file using C
- C program to copy the contents of one file to another file?
- C Program for copying the contents of one file into another file
- Golang Program to Read the Contents of a File
- How to overwrite a file to hide file contents, and make original contents unrecoverable in Linux?
- How to print the contents of array horizontally using C#?
- C# Program to read contents of a file into a string at once
- Operator overloading in C++ to print contents of vector, map, pair ..
- Java Program to Create String from Contents of a File
- How to read contents of a file using Scanner class?
- How to read the contents of a JSON file using Java?
- How to store the contents of arrays in a file using Java?
- How to write contents of a file to byte array in Java?
- How to format contents of a text file in the Linux system?
Advertisements