I don’t think I’ve ever used the return value from a printf() statement. Yes, the function has an int return value, which is the number of characters output. This value can be difficult to guess.
Continue reading
Category Archives: Lesson
Variable Scope
In C programming, variables declared within a function are local to the function. Specifically, they’re the auto storage class, the default. External, or global, variables are defined outside of a function declaration and are of the extern storage class. These variables are available to all functions. But the scope within a function can also be limited, depending on where the variable is declared.
Continue reading
Capturing a Program’s Return Value in Linux
As I wrote in last week’s Lesson, the system() function can’t be used in Linux to obtain a program’s return value. Instead, you must use one of the execl() family of functions. Further, this function must be spawned as a child process. This task involves using the fork() and wait() functions.
Continue reading
Capturing a Program’s Return Value
At the end of the main() function, a return statement must surrender an integer value to the operating system. Does a higher value please the OS? Is it offended by zero? What exactly happens with the value returned when your program is done?
Continue reading
Oops: A (Not Really) 3D Array
I screwed up some code in a most delightful manner, all without knowing what I did. In fact, it was a student who ran my less-than-brilliant code and discovered the obvious flaw. But I was clueless.
Continue reading
My Own strcasecmp() Function – Round Three
The strcasecmp() function isn’t part of the standard C library, though many compilers feature it. As having the function is handy, I wrote about crafting your own version back in 2019. Alas, that implementation is flawed.
Continue reading
A Tally of Unique Words, Part VI
Any mortal programmer would have stopped with last week’s Lesson, where a tally of unique and duplicate words is output. This is the desired result, right? Yes, but it’s an un-orderly list.
Continue reading
A Tally of Unique Words, Part V
The next step in the unique words program is to tally the count of each word. From last week’s Lesson, the word list is sorted, which makes the task of counting duplicates easy.
Continue reading
A Tally of Unique Words, Part IV
In our last episode, the unique words code is able to parse and list individual words in the buffer. To find unique and duplicate words, the next step is to sort the list.
Continue reading
A Tally of Unique Words, Part III
From last week’s Lesson, the text in a buffer is parsed, creating pointers to each word in the string. Alas, the addresses of these words (the pointers) aren’t saved, which is stupid. To handle the job, and to keep the Unique Words project moving forward, a dynamic array of pointers must be allocated.
Continue reading