As if a linked list itself isn’t one of the most terrifying things in C, another beast exists: the double-linked list. It mixes structures and pointers and offers gross potential for extreme mayhem. That sounds like fun!
Continue reading
Category Archives: Lesson
The size_t Variable Type
The C language has its basic variable types: char, int, float, double, struct, and that oddball newbie _Bool. Anything else you see as a “variable” is probably a convenient shortcut manufactured by using a typedef statement. Some of these typedef variables are faily standard, including the most common one, size_t.
Continue reading
Safe Coding Practices – putchar() as a Loop Condition
It’s not unsafe to use putchar() as condition inside a while loop. If you dare try it, however, you must ensure that it checks for file errors. That’s an area where my own code often falls short.
Continue reading
Safe Coding Practices – getchar() and putchar()
I confess that I get sloppy with getchar() and putchar(). These are macros, not functions, but the issue is that their return value is an int, not a char variable. The reason why is important if you want to follow safe coding practices.
Continue reading
Safe Coding Practices – Terminating a String
String constants and strings created or manipulated by C library functions all set that terminating null character, '\0'. When you build your own strings, however, it’s easy to completely forget that null character. I know. I’ve done it.
Continue reading
Safe Coding Practices – String Handling 2
As with the strcpy() function, covered in last week’s Lesson, you run a risk of buffer overflow with strcat(). The compiler doesn’t check for an overflow; to ensure that you’re practicing safe coding habits, that task is up to you.
Continue reading
Safe Coding Practices – String Handling I
C offers a smattering of string-manipulation functions, but it leaves many of the critical issues up to you. Specifically, you must ensure that a string doesn’t overflow its buffer and that all strings are capped with the null character, '\0'.
Continue reading
Safe Coding Practices – scanf()
When it was pointed out to me that using the scanf() functions in my online teaching material was an “unsafe coding practice,” I thought, “Well, duh!” I’ve never been a fan of scanf(); it’s an ugly function.
Continue reading
Safe Coding Practices
Recently, I was notified of some weak programming practices common in beginning C material. As someone who appreciates solid code, I was surprised to hear about these items. As a teacher, I’m quick to address them.
Continue reading
Sorted List Presentation, Part VI
With almost all the former-constants converted to variables, only one puzzle remains: Padding each string’s output so that the columns line up. (Yes, this is the final part of this series!)
Continue reading