14. Strings
Previous lecture chores:
Makefile
Why:
- (repeat) build sequence:
.c → (preprocessor / cc -E) → .c
.c → (translator / cc -S) → .s
.s → (assembler / cc -c) → .o
.o → (linker / cc or ld …) → binary
Many files: first all → .o, then link all *.o
⇒ extra *.o files (so called generates)
Edit one file ⇒ compile one file + link all files
- production graph (dependency)
- age graph (actuality)
Makefile:
- target, sources, recipe:
- Specials:
$@ target
$^ all sources
$< source that initiated recipe
$? all new sources
- ...
- Macro variables
$N (one-letter name) or $(NAME)
Tabulation characters
- (оr .RECIPEPREFIX)
or target: sources; recipe oneliner:
- Default recipes
Default default recipes
look at make -p
Bonus: additional variables (e. g. $(CFLAGS))
Not only compile, but any graph traversal/recreating
Strings
Important
There no such data type as strings
- Variable length
- Locale-aware vs low-level
Conventional LibC string
sequence of bytes
- zero-terminated (s. c. ASCIIZ)
- no metadata
- genres
- Locale-awareness: byte, wide and multibyte
- locale voodoo, e. g. collation, 'A' == 'a' etc.
- Need a buffer to store result
- ⇒ Fixed length
- ⇒ lots of UB and
⇒ n-versions
⇒ Warning check if buffer shall be free()-d
- rule: you allocated — you freed
Exceptions strdup() etc.
- ⇒ Fixed length
H/W
EJudge: QuickSquares 'Quick Squares'
Input two positive integers — W and H, determining size of text screen. Then input a sequence of 5-value series x y width height c, where first 4 values are integers (coordinates of the top left corner of a rectangle and positive width and height of the rectangle), and 5th parameter is printable character. Output screen filled with '.' and all the rectangle draught in order by the corresponded characters. Upper left corner of screen has coordinates (0,0).
24 16 2 0 4 8 * 0 2 14 12 # 20 2 1 1 ! 10 11 8 5 + 3 4 21 7 @
..****.................. ..*..*.................. ##############......!... #.*..*.......#.......... #.*@@@@@@@@@@@@@@@@@@@@@ #.*@.*.......#.........@ #.*@.*.......#.........@ #.*@**.......#.........@ #..@.........#.........@ #..@.........#.........@ #..@@@@@@@@@@@@@@@@@@@@@ #.........++++++++...... #.........+..#...+...... ##########+###...+...... ..........+......+...... ..........++++++++......
EJudge: SlimSquares 'Slim Squares'
Input series of four integers x y w h — position of top-level corner of the rectangle (maybe negative) and it's positive width and height (w and h ⩽ 50 each). The number of sequences is ⩽ 1000. Calculate and display total amount of area occupied by rectangles. Note the coordinates can be any possible integers.
1 1 5 10 3 4 5 6 0 7 12 5 3 6 2 2
96
TODO