Lab10 File Handling
Lab10 File Handling
Instructions:
Create a sub directory named as LabA10.
Give the name of the programs as <R> <A2>1.c, <R> <A2>2.c, …, etc. for the tutorial
problems 1, 2….., respectively. Here <R> implies your Registration No.
Store all the programs under this tutorial part in the directory LabA10.
You should upload your programs to the Moodle course web page. Preferably in ZIP form
latest by 12:45 hrs. today only.
1. Write a program, which reads plain ASCII text from an input file named lab.in and prints the
contents of the file into another file named lab.out such that no line in the output file contains
more than N characters. The value of N is read from the standard input by your program, before it
starts reading the file. The following constraints must be satisfied by your program:
a) void PrintFile(char *fileName); //To print a file, whose name is passed through
filename
b) void CopyFile(char *fileName1, *fileName2); //To verbatim copy the content from
fileName1 to fileName2. If fileName2 already exists,
it should give a warning message and then
overwrite the file.
You should write a main program and call your functions from the main function. Consider a text
file (namely PDS8Lab10.txt) given to you to consider the source file.
a. Define a structure (say struct Student) to store the following information pertinent to a
student.
Name //To store a string of maximum 20 characters
Date Of Birth //To store the date of birth in dd/mm/yyyy format
Marks //To store marks out of 100 as a real number.
b. Read the data of n (n > 10) number of students from keyboard and store them in a file say
“students.dat”.
e. Write a function void SortFile(“student.dat”); to sort all the records in descending order of
the marks of all the students and store back in the same file.
You should write a main program and call your functions from the main function.
[Submit your solutions to Moodle course management system, latest by 12:55 hrs. toady.]