Learn C Language Basics | File Handlings in C programming
We regularly utilize files for putting away data which can be handled by our projects. In this c programming tutorial we are using file structure in our c programs. With a specific end goal to store data forever and recover it we have to utilize files.
Files in C programming are not only used for data reading but also for data writing, manipulation and many more option thanks to C programming built in functions. Our C programs are also stored in files.
Note : Stdio.h library should be added in order to use file handling functions such as basic input output functions in C programming language.
Following are the file handling function that could be used in C programming language
Functions Used In C Programming with Description
fopen() --- New file creation or open an existing file in c programming.
fclose() --- Close a file in c programming.
getc() ---- Read character from a file.
putc() ---- Writes a character to a file.
fscanf() --- Reads specific set of data from a file.
fprintf() -- Writing specific set of data to a file.
getw() --- Reads an integer from a file.
putw() --- Writes an integer to a file.
fseek() --- Setting the location to required point.
ftell() ---- returns current location in the file.
rewind --- Set the location to the beginning of point in c programming.
Modes of operation in c:
This is used when a file is used for writing
#include <stdio.h> // library
FILE *fopen(), *fp;
fp = fopen("prog.c","r");
c = getc(fp) ;
while (c!= EOF)
c = getc(fp);
This is used when a file is opened for writing
file = fopen("file.txt","w"); /*Create a file and add text*/
This is used when a file is opened for appending
file = fopen("file.txt","a");
fprintf(fp,"%s","This is just an example :)"); /*append some text*/
C Programming Modules
2 . Data Types
5 . Decision Making
6 . Loops
7 . Arrays
8 . Functions
9 . Pointers
10 . String Handling
11 . File Handlings
12 . Storage Classes
13 . Preprocessing