My first C program!
·——
····
··
—
·····
···——
——···
After
my first C contribution last month, I've now written
my first C program! It's a port
from Python of
this weekend's Easy Password Generator.
Both versions are implemented as a CGI, with
the C version benchmarking about 500% faster than
the Python version. (~100 req/sec vs. ~20). Both programs read a
template.html file in the same directory, and interpolate a string into the
<head> tag—a possible redirect to HTTPS—and two more into the
<body>—a list of passwords (taken from
apg(1)), and a Python/C version indicator.
Working with streams in C was pretty easy, whether stdin/out, process pipes, or filesystem files. However, I struggled to convert streams into strings (aka "character arrays"): first, getting the template off the filesystem, and then parsing the
apg(1) output. I'm particularly confused by the relationship between pointers and arrays. The crux of the matter, I think, is that "the value of [an] array is the address of element zero of the array" [
K&R, 99], but it will take more practice to grok that. I suspect, then, that my "
char PAGE[1024 * 50]" and "
int append(...)" hacks look quaint at best, and that memory allocation is also going to factor into things very soon.
·——
····
··
—
·····
···——
——···
Feed back to
Chad Whitacre.