The swap() Function

Difficulty: ★ ★ ★ ☆

Swapping values is common task in computer programming, often used when sorting. You need the value of variable a in variable b and vice-versa. A number of methods are available for swapping, most of which involve using a temporary variable to hold one of the values during the swap.
Continue reading

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