Computer programming - Lab 8

1. Write your own implementation of the strstr function which returns a pointer to the first occurrence of the second string parameter in the first.

2. Write your own implementation of the strcmp and strncmp functions which compare two strings (entirely or the first n characters) and return an integer < 0, 0 or > 0 if the first string is less than (alphabetically earlier), equal or greater than the second.

3. Write your own implementation of the strtod function (for floats in base 10, no need to handle hexadecimal floats).

4. Write your own implementation of the strspn and strcspn functions which return the length of the first segment of string parameter one which consists entirely of characters that appear/do not appear in parameter two.
These functions are better alternatives to strtok since they do not change the destination string.

5. Write a function that takes a string and prints on one line each all words in the string. Words are formed of any characters except whitespace and colon, comma, semicolon, period, question mark and exclamation mark. Use strspn / strcspn as needed.

6. Write a function that takes as parameter a string and fills an array with addresses to the beginning of each (whitespace-separated) word in the string (similar to the argv[] array of main). The array and its available length are also given as parameters. Terminate the array with a NULL pointer after the last valid address.

7. Write a function that takes a NULL-terminated array of strings (char *), another string buf and a maximal length, and concatenates all strings from the array into buf, separated by one space, without exceeding the length limit. Avoid strcat and maintain a pointer to the end of the string being constructed.

8. Implement a function sscanprint with two parameters having the same meaning as in sscanf, but which simply prints the fields matched according to the format, one per line. Implement the format specifiers %d, %f and %MAXs, regular characters and whitespace. Return the same value as sscanf.


Marius Minea
Last modified: Wed Nov 18 21:45:00 EET 2015