2 Marks Definition Answers, Multiple Choice Questions, True/False - Computer Programming C: UNIT V: File Operations
2
Marks Definition Answers
•
Files are comprised of one or more records. Each record in a file should
describe a unique collection of fields. Files can be used to store all types of
information, such as student or employee data. Data files are normally
associated with various database processes in which information can be managed
in non‒volatile states, such as a disk drive.
•
Bits are also known as binary digits, bits are the smallest value in a data
file. Each bit value can only be a 0 or 1.
•
Bytes provide the next step in the data file. Bytes are most commonly made up
of eight bits and used to store a single character, such as a number, a letter,
or any other character found in a character set.
•
In database or data‒file, groupings of characters are most commonly referred to
as fields.
•
Records are logical groupings of fields that comprise a single row of
information or record. Each field in a record describes the record's
attributes. When the data is stored in a file, it is stored permanently.
•
This means that even through the computer is switched off, the data cannot
removed from the memory since the file is stored on perminant memory. This file
data can be utilized as and when required.
•
It is possible to update the data. For example, we can add new data to the
existing file, delete unnecessary data from the file and modify the available
data of the file
•
Files are highly useful to store huge amount of data.
•
Text: An organized sequence of
characters. A text stream allows certain character translations, depending on
the environment. As a result, there may not be a one‒to‒one relationship
between what is written and what is read.
•
Binary: A sequence of bytes stored
as they are written and read as they are stored. These differ from text streams
because there is no translation of characters and these are read in the same
way in which they are stored.
•
A data file must be opened before it can be created or processed, this
associates the file name with buffer area.
Syntax:
FILE
*fp;
fp=fopen("filename",
"mode");
•
When an 'r' mode used, the file is opened for reading, a'w' is used to indicate
a file to be used for writing, and an a indicates that you desire to append
additional data to the data already in an existing file.
•
A file must be closed after all the operation of the file have been completed.
Syntax:
fclose(file‒pointer);
•
A data file must be created before it can be processed. In two ways a stream‒
oriented data file can be created. One is using a text editor or a word
processor to create the file directly.
•
Once the file is in opened mode, as usual we can write() method to append the
strings to the file. After writing the data, without closing the file, we can
read strings from the file of all, we should place the file handler to the
beginning of the file using seek() method as:
Syntax:
f.seek(offset, from where)
•
The file object provides a set of access methods to make our lives easier. We
would see how to use read() and write() methods to read and write files
•
The operating system (os) module has a sub module by the name 'path' that
contains a method isfile(). This method can be used to know whether a file that
we are opening really exists or not.
•
When you are searching through data in a file, it is a very common pattern to
read through a file, ignoring most of the lines and only processing lines which
meet a particular condition. We can combine the pattern for reading a file with
string methods to build simple search mechanisms.
•
Directly going to any byte in the binary file is called random accessing. This
is possible by moving the file pointer to any location in the file and then
performing reading or writing operations on the file as required.
•
Random accessing is also possible using mmap (memory mapped file) module.
•
Zipping and unzipping of a fine can be done using ZipFile class of zipfile
module.
•
The error function reports the statistics of the file indicated. It also takes
a file pointer as its argument and returns a non zero integer, if an error has
been detected upto that point, during processing otherwise it returns zero
•
perror() is a standard library function which prints the error messages
specified by the complier.
MULTIPLE CHOICE QUESTIONS
1. The first and second arguments
of fopen are
a)
A character string containing the name of the file & the second argument is
the mode.
b)
A character string containing the name of the user & the second argument is
the mode.
c)
A character string containing file poniter & the second argument is the
mode.
d)
None of the mentioned of the mentioned
2. For binary files, a ________
must be appended to the mode string.
a)
Nothing
b)
"b"
c)
"binary"
d)
"01"
3. If there is any error while
opening a file, fopen will return
a)
Nothing
b)
EOF
c)
NULL
d)
Depends on compiler
4. Which is true about getc.getc
returns?
a)
The next character from the stream referred to by file pointer
b)
EOF for end of file or error
c)
Both a & b
d)
Nothing.
5. When a C program is started, O.S
environment is responsible for opening file and providing pointer for that
file?
a)
Standard input
b)
Standard output
c)
Standard error
d)
All of the menitoned
6. FILE is of type ______?
a)
int type
b)
char * type
c)
struct type
d)
None of the mentioned
7. What is the meant by 'a' in the
following operation?
fp = fopen("Random.txt",
"a");
a)
Attach
b)
Append
c)
Apprehend
d)
Add
8. Which type of files can't be
opened using fopen()?
a)
.txt
b).bin
c)
.c
d)
None of the mentioned
9. Which of the following fopen
statements are illegal?
a)
fp = fopen("abc.txt", "r");
b)
fp = fopen("/home/user1/abc.txt", "w");
c)
fp = fopen("abc", "w");
d)
None of the mentioned
10. What does the following segment
of code do?
fprintf(fp, "Copying!");
a)
It writes "Copying!" into the file pointed by fp
b)
It reads "Copying!" from the file and prints on display
c)
It writes as well as reads "Copying!" to and from the file and prints
it
d)
None of the mentioned
11. FILE reserved word is
a)
A structure tag declared in stdio.h
b)
One of the basic datatypes in c
c)
Pointer to the structure defined in stdio.h
d)
It is a type name defined in stdio.h
12. What is the output of this C
code?
#include <stdio.h>
int main()
{
FILE *fp = stdin;
int n;
fprintf(fp, "%d", 45);
}
a)
Compilation error
b)
45
c)
Nothing
d)
Depends on the standard
TRUE/FALSE
1.
If there is any error while opening a file, fopen will return null.
True/False
2.
Byte is the smallest value in a data file
True/False
3.
Grouping of characters are also called as fields
True/False
4.
Records are groupings of fields that comprise of double row of information or
record
True/False
5.
Files are comprised of only one record.
True/False
6.
A stream is a continuous series of bytes that flow into or out of program
True/False
7.
fprintf and fscanf are not similar to scanf and printf.
True/False
8.
The sequential access is disadvantage.
True/False
9.
ftell() function is used to specify the current position of the file.
True/False
10.
FILE is of static type.
True/False
11.
The FILE type in C is a basic data type like int or char.
True/False
12.
The fopen() function returns NULL if there is an error opening the file.
True/False
13.
The "w" mode in fopen() truncates the file if it already exists.
True/False
14.
fprintf() can only be used to write strings to a file.
True/False
15.
fclose() should be called for every file opened using fopen() to release system
resources.
True/False
16.
feof() returns true if the end‒of‒file indicator is set for the specified
stream.
True/False
17.
fseek() can be used to move the file pointer to any position within a file,
including before the beginning of the file.
True/False
18.
Binary files are always opened with the "b" modifier (e.g.,
"rb", "wb", "ab").
True/False
19.
rewind() is preferred over fseek() for repositioning the file pointer to the
beginning of a file because it provides error checking.
True/False
20.
It is safe to perform file operations on a file pointer that has been closed
using fclose().
True/False
Computer Programming C: UNIT V: File Operations : Tag: Computer Science : Computer Programming C - File Operations in C Programming : 2 Marks Definition Answers
Computer Programming C
CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
English Essentials I
EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
தமிழர் மரபு - Heritage of Tamils
UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Calculus
MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I
PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Chemistry I
CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Makerspace
ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming C
CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming Python
CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Fundamentals of Electrical and Electronics Engineering
EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Mechanical Engineering
ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Civil Engineering
CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing
CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I Laboratory
PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Applied Chemistry I Laboratory
CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming C Laboratory
CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming Python Laboratory
CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Engineering Drawing
ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation
Basic Electronics and Electrical Engineering
EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing - Laboratory
CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation