Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views3 pages

Unit 5

The document discusses file processing in C, highlighting the importance of files for data preservation and transfer. It covers types of files, file operations, methods for opening and closing files, and access methods (sequential and random). Additionally, it introduces command line arguments and specific functions for file handling, such as fprintf() and fscanf().

Uploaded by

thilagavathy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Unit 5

The document discusses file processing in C, highlighting the importance of files for data preservation and transfer. It covers types of files, file operations, methods for opening and closing files, and access methods (sequential and random). Additionally, it introduces command line arguments and specific functions for file handling, such as fprintf() and fscanf().

Uploaded by

thilagavathy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

UNIT -V

FILE PROCESSING
PART A
1. Why files are needed?
When a program is terminated, the entire data is lost. Storing in a file will preserve
your data even if the program terminates. If you have to enter a large number of
data, it will take a lot of time to enter them all. However, if you have a file
containing all the data, you can easily access the contents of the file using few
commands in C. You can easily move your data from one computer to another
without any changes.

2. Types of Files
When dealing with files, there are two types of files you should know about:
1. Text files
2. Binary files

3. Enlist the File Operations.


In C, you can perform four major operations on the file, either text or binary:
1. Creating a new file
2. Opening an existing file
3. Closing a file
4. Reading from and writing information to a file

5. How to open a file?


Opening a file is performed using the library function in the "stdio.h" header file:
fopen().
The syntax for opening a file in standard I/O is: ptr = fopen("fileopen","mode")

6. How to close a file?


The file (both text and binary) should be closed after reading/writing. Closing a
file is performed using library function fclose(). fclose(fptr);
7. What are two main ways a file can be organized?
1. Sequential Access — The data are placed in the file in a sequence like beads on
a string. Data are processed in sequence, one after another. To reach a particular
item of data, all the data that proceeds it first must be read.
2. Random Access — The data are placed into the file by going directly to the
location in the file assigned to each data item. Data are processed in any order. A
particular item of data can be reached by going directly to it, without looking at
any other data.

8. What is file?
A file is a semi-permanent, named collection of data. A File is usually stored on
magnetic media, such as a hard disk or magnetic tape.

9. State Transaction Processing.


As data flows into an organization, the files that keep track of the data must be
updated. For example, data flows into a bank from other banks and ATM
machines. Often this data is gathered as it occurs into a transaction file.

10. What is command line arguments?


It is possible to pass some values from the command line to your C programs
when they are executed. These values are called command line arguments and
many times they are important for your program especially when you want to
control your program from outside instead of hard coding those values inside the
code

11. Write the functions for random access file processing.


1. fseek()
2. ftell()
3. rewind()

12. Write short notes on fprintf ().


This function is same as the printf() function but it writes the data into the file, so it
has one more parameter that is the file pointer.
13. Write short notes on fscanf ().
This function is same as the scanf() function but this reads the data from the file, so
this has one more parameter that is the file pointer.

Part –B
1. Explain about files and with it types of file processing.
2. Compare sequential access and random access.
3. Write a C program to read name and marks of n number of students from user
and store them in a file.
4. Write a C program to read name and marks of n number of students from user
and store them in a file. If the file previously exits, add the information of n
students.
5. Write a C program to write all the members of an array of strcures to a file using
fwrite(). Read the array from the file and display on the screen.

You might also like