$25
1. Write a C program consisting of the following functions to create a library. You cannot use any standard library function.
• int printStr(char *) – prints a string of characters. The parameter is terminated by ’\0’. The return value is the number of characters printed.a
• int readInt(int *n) – reads a signed integer in ‘%d’ format. Caller gets the value through the pointer parameter. The return value is OK (for success) or ERR (on failure).
• int printInt(int n) – prints the signed integer (n) with left-alignment. Printing sign for a negative number is mandatory while for a positive number it is not required. On success, function will return the number of characters printed and on failure it will return ERR.
• int readFlt(float *f) – reads a floating point number in ‘%f’ format (for example, –123.456). Caller gets the value through the pointer parameter. The return value is ERR or OK.
• int printFlt(float f) – prints the floating point number (f) with left-alignment. Printing sign for a negative number is mandatory while for a positive number it is not required. However, decimal point should be printed to differentiate it from an integer number. Returns the number of characters printed (on success) or ERR (on failure).
Use only the following header file for your C program.
/* Header file for Assginemnt 2: Name it as myl.h */
#ifndef MYL H
#define MYL H
#define ERR 0
#define OK 1
int printStr(char *); int printInt(int); int readInt(int *); int readFlt(float *); int printFlt(float);
#endif
1
2. Name of your .c file as ass2 roll.c, where roll is your roll number. Include only ”myl.h” as your header file. It should not contain the function main(). Write your main() function in a separate file. Use Makefile to test your library. Move your main.c, myl.h, Makefile and ass2 roll.c in folder asgn2 roll. Zip the folder and upload as a single file in the moodle server.