Computer programming - Lab 3

Processing numbers

1. Hex printing Write a function that prints a number, digit by digit, in base 16.

2. Read a C integer Write a function that returns an unsigned number read from input either in 8 (starts with 0), base 16 (starts with 0x or 0X) or base 10 (default).

3. Thousands separators Write a function that returns a number read from input with mandatory comma as a thousands separator. That is, reading 1,234,567 should return the number 1234567.

Character processing

4. Words in line Write a program that counts the words in one input line. A word is a sequence of characters which are not whitespace (isspace()).

5. Word count The Unix program wc counts the number of characters, words and lines in the input (or in any file). A word is a sequence of non-whitespace characters (i.e., isspace() returns false).
Write a program that in addition to printing total chars, words and lines in the input:
a) prints for any line the number of words in that line
b) prints the number of lines in each paragraph. Paragraphs are separated by at least one empty line (only the newline character).

Formatted files

6. SVG path length. An SVG path consists of the following commands: L or l (draws a line from the current point to the indicated coordinates), M or m (moves the current point), each followed by two real numbers, representing x and y coordinates (absolute for uppercase commands, relative for lowercase). Commands are separated by whitespace. Write a program that reads a sequence of commands and computes the total length of the path drawn. Initial coordinates are assumed (0, 0). You may use the following function to read a number:
double readf(void)
{
  double x = 0;
  scanf("%lf", &x);
  return x;
}
Marius Minea
Last modified: Tue Oct 7 23:45:00 EEST 2013