Computer programming - Lab 8: Strings, I/O, review

Strings

1. String compare Implement your own versions of strcmp and strncmp.

2. Definitions in strings Write a function that takes a string, prints all definitions of the form name=value from the string, one per line, and returns their number. name must be an identifier (like in C: starts with letter or underscore, may contain letters, underscore and digits). value may contain arbitrary non-whitespace. Definitions must be separated by whitespace from other parts of the string.

Input/Output

3. Function-like terms A term is a variable (string of letters) or an unsigned integer or a function (string of letters) of at least one term given in parantheses and separated by commas, e.g. func(g(x,23),abc,f(h(2))). Write a function that reads a term (must be ended by whitespace or EOF) from input and returns 1 if correct, else 0 and reports the first error.

4. Define and replace Write a program that reads input, identifies the first line of the form #define somename restofline (where somename is a C identifier), separated left and right by whitespace, and prints the remaining input substituting any standalone occurrence of somename with restofline.

5. Recursive XML tags XML tags are of three kinds: start tag <somename>, end tag </somename> or empty element tag: <somename some other chars/>. There may be arbitrary text between tags.
Write a program that reads input (assumed to be XML) and checks if the open and close tags are properly nested, with matching tag names.
Hint: Try to write a recursive definition of XML text and structure your code accordingly. When finding a start tag do a recursive call that ends when a matching end tag is found.

See also the problems processing input with recursive structure from Lab 3 and Lab 4.


Marius Minea
Last modified: Tue Nov 14 13:30:00 EET 2017