Computer programming - Lab 8

1. Integers and reals Write a function that takes a string and prints out all numbers in the string, prefixed with "int" or "float", depending on their format. Recognize and print also numbers that are adjacent to other text.

2. Command-line options Write a program that reorders the command-line argument array argv[], placing all strings that start with '-' first, followed by all other strings.

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 16 17:00:00 EET 2016