The standard C library contains a clutch of functions you use all the time, such as printf(), getchar(), malloc(), time(), rand(), and others. If you look in the library, you may discover some oddball functions that you’ve never used. One of those oddball functions might be ungetc().
Continue reading
Defensive Input – Solution
Writing an input routine isn’t that difficult in C. I cobble together simple input routines all the time. The scanf() function is brilliant for such situations. When you have to test input, things get dicey, which I hope you discovered as you attempted this month’s exercise.
Continue reading
Your Own strdup() Function
In last week’s Lesson, I demonstrated the strdup() function. That function isn’t available in every C language library, but it’s easy to craft your own.
Continue reading
Defensive Input
The task is rather simple: Prompt the user to input a value between 1 and 9. If you’ve read the first few chapters of any of my For Dummies C programming books, you could do that one easily. But what happens when the user doesn’t type a value in that range or — worse — they type text instead?
Continue reading
To Copy or to Duplicate a String
The C library function to copy a string is strcpy(), which (I’m guessing) stands for string copy.
Continue reading
99 Bottles of Beer
This month’s Exercise involves coding the lyrics for a cumulative song. Perhaps the most famous, and certainly the most obnoxious, cumulative song is the old warhorse, 99 Bottles of Beer.
Continue reading
Check That Sum
The old computer processing adage is “garbage in, garbage out.” What it means is that unless your data is good, don’t expect to see good results. So what can be done to ensure that the data is good? A checksum, that’s what.
Continue reading
Merry Cumulative Song Exercise – Solution
I crafted my solution to the cumulative song exercise by separating the parts of the song that are repeated from the unique text. Specifically, the ordinal days are unique as well as the gifts. The rest of the text is sung over and over.
Continue reading
Encoding and Decoding, Part VII
The final part of the decoding program performs the actual decoding: A two-byte hexadecimal string is converted into a value. That value is then manipulated by the XOR 0xAA operation. The result is output. Yep, it took a long time to get to this point.
Continue reading
Merry Cumulative Song Exercise
In my C programming books, I often use the directions on a shampoo bottle as an example of basic programming:
1. Lather.
2. Rinse.
3. Repeat.
Another real-life example of programming techniques happens in music. Specifically, cumulative songs are representative of loops. This type of song includes 99 Bottles of Beer and the holiday favorite, The Twelve Days of Christmas.
Continue reading