Dsa Assignment
Dsa Assignment
Text and Binary are the file types that you should have a basic idea before moving further into
the topic.
1. TEXT FILES –
A text file contains textual information in the form of alphabets, digits and special characters
or symbols.
This file can be created using a text editor and can be read and understood by a human
being as they are in plain language.
2. BINARY FILES –
On the other hand, a binary file contains bytes or a compiled version of a text file i.e. data
in the form of 0’s and 1’s. They can hold higher amount of data, are not readable easily and
provides a better security than text files.
FILE *fp;
fp = fopen(“fileName.txt”, “w”)
The second parameter can be changed to contain all the attributes listed in the
above table.
FILE * fp;
fp = fopen(“fileName.txt”, “r”);
Writing a file –:
The file write operations can be perfomed by the functions fprintf and fputs with
similarities to read operations. The snippet for writing to a file is as :
FILE *fp ;
fp = fopen(“fileName.txt”, “w”);
Closing a file –:
After every successful fie operations, you must always close a file. For closing a file,
you have to use fclose function. The snippet for closing a file is given as :
FILE *fp ;
fclose(fp)