Finding Characters

Difficulty: ★ ★ ☆ ☆

When I was working on last month’s Exercise, I scoured the C library for a function that returned the number of specific characters found in a string. The closest I could find was strchr(), which returns the location of a given character in a string. You can set this function in a loop to find subsequent characters, but what I needed was a tally, a total count of all matching characters in the string.
Continue reading

Yesterday

Difficulty: ★ ★ ☆ ☆

The time.h header defines a handful of functions useful for discovering and manipulating today’s date. Especially the localtime() function, which translates a time_t (Unix Epoch) value into date fields for output or manipulation. It’s a wonderful tool, but what does it tell you about yesterday?
Continue reading

A Compact for Loop

Difficulty: ★ ★ ☆ ☆

A for loop statement contains three parts: initialization, termination, and while-looping. If you omit any part, the compiler assumes the value one, or TRUE, as the value, so the statement for(;;) becomes an endless loop. The opposite of omitting is loading up: You can state multiple initialization and while-looping expressions in the statement, which can make a for loop truly compact.
Continue reading