The Pragmatic Programmer: From Journeyman to Master

Exercises

11.

Your C program uses an enumerated type to represent one of 100 states. You'd like to be able to print out the state as a string (as opposed to a number) for debugging purposes. Write a script that reads from standard input a file containing

name state_a state_b : :

Produce the file name.h, which contains

extern const char * NAME_names[]; typedef enum { state_a, state_b, : : } NAME;

and the file name.c, which contains

const char * NAME_names[] = { "state_a", "state_b", : : };

12.

Halfway through writing this book, we realized that we hadn't put the use strict directive into many of our Perl examples. Write a script that goes through the .p1 flies in a directory and adds a use strict at the end of the initial comment block to all flies that don't already have one. Remember to keep a backup of all flies you change .

Категории