Programming in C
autumn 2008
Exercise 6
To the exam you may take one A4 paper, where you have make your own notes.
You can use both sides of the paper.
Oct. 13 2008
-
Change the assigment one and two of the exercise five so that you use modules.
The implementation of the event queue should be in its own module.
Add into the code some asserts, so that you can be sure that you program is
working logically right.
Write a function that searches a given character. The function has as parameters
a string and a character. The function returns a pointer to the first occurence
of the searched character in the string. If the character is not found NULL is
returned. Write also a main program from where the function is called.
- (11-12)
In this exercise we use a binary file "fname" storing information
about employees. For each employee, store the name,
the identification number and a salary:
struct employee {
long id;
char name[50];
double salary;
};
Write the following functions:
-
int add (fname, empId, stringName, salary), where
fname is a string representing a binary file
empId is an integer,
stringname is a string, and a
salary is a double.
This function appends a new employee to the binary file
(an empId is akey and uniquely identifies an employee;
therefore this function may fail)
-
void moreDollars (fname, empId, incr), with three parameters: a string
fname, an integer empId, and a double incr.
This function operates on a binary file fname, and it increases by
incr the salary of every employee whode id is greater than or equal to
empId.
-
void show (const char *fname) that shows all the information stored
in the binary file fname
Write a program find that takes as command line arguments a file name and
a string (find file1 Java).
Program prints all those lines that have the given string.