Arrays
Arrays
File handling refers to the method of storing data in the C program in the form of an
output or input that might have been generated while running a C program in a data
file, i.e., a binary file or a text file for future analysis and reference in that very
program.
What is a File in C?
A file refers to a source in which a program stores the information/data in the form of
bytes of sequence on a disk (permanently). The content available on a file isn’t
volatile like the compiler memory in C. But the program can perform various
operations, such as creating, opening, reading a file, or even manipulating the data
present inside the file. This process is known as file handling in C.
Text Files
Binary Files
Text Files
The text files are the most basic/simplest types of files that a user can create in a C
program. We create the text files using an extension .txt with the help of a simple
text editor. In general, we can use notepads for the creation of .txt files. These files
store info internally in ASCII character format, but when we open these files, the
content/text opens in a human-readable form.
Text files are, thus, very easy to access as well as use. But there’s one major
disadvantage; it lacks security. Since a .txt file can be accessed easily, information
isn’t very secure in it. Added to this, text files consume a very large space in storage.
To solve these problems, we have a different type of file in C programs, known as
binary files.
Binary Files
The binary files store info and data in the binary format of 0’s and 1’s (the binary
number system). Thus, the files occupy comparatively lesser space in the storage. In
simpler words, the binary files store data and info the same way a computer holds
the info in its memory. Thus, it can be accessed very easily as compared to a text
file.
The binary files are created with the extension .bin in a program, and it overcomes
the drawback of the text files in a program since humans can’t read it; only
machines can. Thus, the information becomes much more secure. Thus, binary files
are safest in terms of storing data files in a C program.
used to set the file pointer to the intended file position fseek()