I suffer from compulsory C review disorder, so just a few quick points:
- The pattern "x = realloc(x, ...)" is a bad idea, it leaks the original memory on failure. Since the code seems to car about its memory management (and since it's a tutorial), I think this is worth mentioning (and fixing).
- I generally recommend against scaling string allocations by sizeof (char); that's always 1 so it doesn't do anything. Some people seem to feel that it's part of a general usage pattern that makes the intent more clear, though.
- I would recommend more "const" and "static", but some people seem to not care.
- I would use more size_t rather than int for things that are sizes. This is more clear, and also safer since it's unsigned.
- Using strtok() is not always the best choice, it has issues, but here it's basically doing what it was designed to do I guess.