Parsing is an activity that programmers are often reluctant to do themselves. That’s because parsing can be a real pain in the rump. Not only that, but why write your own function when you can use specific libraries that handle the job for you? That’s a blessing, but it won’t let you escape from attempting this month’s Exercise.
Continue reading
Author Archives: dgookin
The errno Variable
One of the C language’s universal variables is errno. It contains a code describing details about why a particular operation failed. You can use errno in your code to provide better, more informative error messages for your programs.
Continue reading
Your Code Goes “Oops!”
Error messages have a notorious reputation in the computer kingdom. It’s well-deserved, but as a programmer you can better see how error messages evolved. Like documentation, i.e., the wretched manual (which is gone now), error messages are typically an afterthought in the software development cycle. It doesn’t have to be that way.
Continue reading
Give Me a break
I received an email question recently about the power of the break keyword. The answer to the question is that you can only break out of the current loop or switch-case structure. Even in a nested loop, or a switch-case structure within a loop, break affects only the current element.
Continue reading
The ungetc() Function
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