You are on page 1of 2

Section 8

PDS Lab Lab-10 10.11.2016


 

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) No word should be broken. If a word cannot be fitted in a line without exceeding N


characters, then the whole word should be moved into the next line. Assume that the text
contains only alphanumeric characters, blanks, and new-line characters. Blanks and new-
line characters act as delimiters between words.
b) Paragraphs of the original text should remain as paragraphs of the final text. Paragraphs are
separated by on ore more empty lines. You may assume that empty lines do not contain
blanks.
c) If a word in a paragraph can be fitted into the previous line of the same paragraph, then it
should be moved into the previous line.
d) Your program should not read the whole input file into memory. It should read only a line
at a time (or perhaps two at a time). Writing into the output file should be interleaved with
the reading of the input file.

2. Write the following functions in C programming language.

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.

c) void FrequncyCount (char *fileName1); //To count the frequency of alphabets in


the file. Ignore the numeric character and
punctuation symbols, if any and consider both
lower and upper case of a character is same.

d) void CopyReverse(char *fileName1, *fileName2); //To copy the content from


fileName1 to fileName2, but in reverse order. For
example, if the input file is “abc, xyz mnp.”, then output
file should be “mnp. xyz abc,” etc.
[Hint: You can use stack implemented with linked list structure.]

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.

3. Write the following codes in C programming languages.

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”.

c. Write a function struct Student ReadFromFile(“student.dat”, char *name); to read a


record, whose student’s name is name. Print the record then.

d. Write a function void DeleteFromFile(“student.dat”, char *name); to delete a record from


the file student.dat, whose student’s name is name. Print the updated file after the delete
operation, if it is successful.

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.]

You might also like