Many first-time programmers rush over variable type descriptions and head full-bore into coding. That’s fine. I did it. You probably did it. But eventually you encounter code that doesn’t work properly because of negative numbers. That’s when you go back and review the concept of negative integer variable types.
Continue reading
Category Archives: Lesson
String Storage Mysteries
String storage is one of those frustrating things in the C language. Specifically, it’s that null character, \0, that appears at the end of every string. Is that character counted when you input a string? Copy a string? Create storage for a string? It’s a mystery that could drive you nuts.
Continue reading
The pow()erful Function
When I first learned the C language, I was surprised to find something missing from its assortment of operators. The +, -, *, and / operators are pretty common for nearly all programming languages. And you’ll find the % and ! operators used for modulus and logical NOT in a few programming languages. Yet what other languages have that C lacks is an exponent or power operator.
Continue reading
All Files Have a Number
The common way for humans to describe a file is to use its name. You refer to hello.txt as a file. The fopen() function C uses this nomenclature, which is handy and convenient. While a program runs, however, a file number is assigned to an open file.
Continue reading
A Solution for 100 Doors
When I code a program, I start out by slapping together the various elements. I setup the variables, I write some quick routines, and I add comments to the tune of /* Do something here*/. With those bricks in place, I go back and fill in the mortar to make it all work. If the code runs, great! That rarely happens, so more work is involved.
Continue reading
The Problem of 100 Doors
Plenty of interesting and fun programming puzzles are available to test your skills. Some of these puzzles come from the realm of mathematics or logic. What those propellerheads do with the solutions is up to them, but often you can code such problems to help you learn more about programming. One such logic problem is called 100 Doors.
Continue reading
Macros with Variables
Some C coders really go nuts with macros. I’m not a big fan of those people.
Continue reading
User-Defined Functions and Macros
When you desire to do something specific in your program, or have a chunk of code that’s duplicated elsewhere, you craft a function. That’s the traditional, problem-solving approach, and the C language is full of functions. Yet sometimes, programmers build macros instead of functions.
Continue reading
Writing a Wide Bit Field
Writing a chunk of bits into an integer at a specific position requires major application of binary manipulation. That sounds impressive and mystical. To put it another way, writing a bit field is like using a stencil to paint a wall: You create the stencil, set it in place, then you slap down the paint.
Continue reading
Reading a Wide Bit Field
The same programming kung fu used to read a single bit also applies to wide bit fields. The process involves masking and shifting: You must know the bit field’s width and position in an integer value. Once those values are obtained — no matter how wide the bit field — a single function handles the job.
Continue reading