Computer programming - Lab 4

1. Fixed-width printing Write a function that takes an unsigned n as parameter, and prints a text read until end of input, fitting n characters per line. Words (sequences of non-whitespace chars) are printed with one space in between. A word that would exceed the line limit will be split inserting a hyphen - as last character on the line (no extra hyphen is needed if the last character that fits is a hyphen itself). Newlines in the original text are observed.
Hint: to handle the end of the line, write a function peek() which returns the next character without consuming it (use ungetc()).

2. Prettyprinting Write a program that properly indents a text read from standard input that has balanced braces { } . The output is formed as follows:

3. Continued fractions A continued fraction has the form 1/(a1+1/(a2+1/(a3+1/.../an))) where ai are positive integers.
Write a function that reads a continued fraction from input and returns its value as floating-point number.

4. Stacked expressions A stacked expression is either an unsigned number or an expression of the form (number op stackedexpr) where op may be + or *.
Example: (4 * (2 + (3 * 5))). Whitespace is optional.
Write a function that reads a stacked expression and returns its value.


Marius Minea
Last modified: Wed Oct 21 21:15:00 EEST 2015