2 Programming assignment
The teaching goal of this assignment is to get used to the C
programming environment and learn the basic of how libraries work.
What you must do, in a nutshell:
- implement my_strlen and my_strcmp;
- implement a test program that uses these two functions;
- create a Makefile containing rules to build a library containing
the two functions, and the test program.
2.1 The two functions
You must implement the following two functions:
unsigned long my_strlen(const char *s);
int my_strcmp(const char *s1, const char *s2);
- my_strlen must behave like the function strlen from the
standard C library. See strlen(3) for details.
- my_strcmp must behave like the function strcmp from the
standard C library. See strcmp(3) for details.
- my_strlen must be implemented in a file named my_strlen.c.
- my_strcmp must be implemented in a file named my_strcmp.c.
- the two function prototypes must be declared in a .h
file, in accordance with the C coding standard.
- you must not include any system header in your code.
- you must not use any function from the C standard library in your code.
2.2 The test program
You must implement a program which takes either one or two
arguments on the command line:
- if one argument is provided, it must return its length as exit code.
- if two arguments are provided, it must return the result of their
comparison as exit code.
The program must be implemented in a file named test.c. Again, you
must not include any standard/system header nor use any function from
the standard C library.
2.3 The Makefile
Your Makefile must contain rules to build:
- libminic.a, a static library containing the two functions;
- test, the test program, linking with -lminic.
Ensure that your Makefile also follows the section “Build rules”
in the C coding standard.
5 Copyright and licensing
Copyright © 2014, Raphael ‘kena’ Poss. Permission is granted to
distribute, reuse and modify this document and other documents for the
Systems Programming course by the same author according to the terms
of the Creative Commons Attribution-ShareAlike 4.0 International
License. To view a copy of this license, visit
http://creativecommons.org/licenses/by-sa/4.0/.