Drawing cards from a deck is an activity requiring more effort than flagging an element in an array, which was demonstrated in last week’s Lesson. Such code works, but it’s best to set details about the card when it’s drawn, noting its face value and suit, for example. Such complex information is best placed into a structure.
Continue reading
Author Archives: dgookin
Next Tuesday – Solution
One way to discover next Tuesday’s date is just to wait. You could code that solution in C, which would be silly, but I hope that you instead chose to use some time functions to derive your answer.
Continue reading
Draw Five Cards (Poker I)
To code a card game, you must start with the deck: 52 cards divided into 4 suits each consisting of 10 number cards and three face cards. Seems easy.
Continue reading
Next Tuesday
What’s today?
The reply could be the day of a week, such as Sunday. That’s how I first answer the question. The more detailed answer is the day of the month, which isn’t often on my mind — unless it’s an important day like a birthday or some event.
Continue reading
Structures and Arrays, Part III
I’ve wrapped up most of the oddities about structure/pointer/array notation in the past two Lessons (Part I and Part II). All that’s left is for me to go insane and start allocating structures as pointers with all their members as pointers.
Continue reading
Structures and Arrays, Part II
When it comes to structures and pointers, the structure-pointer notation is used only when the structure itself is allocated as a pointer (block of memory), not when a structure member is a pointer. Let me review from last week’s Lesson:
Continue reading
Structures and Arrays, Part I
Structures in C have their own issues when it comes to structure-pointers and structures within pointers. I wrote about this issue a few months back.
Another structure issue occurs with arrays within structures and arrays of structures. It also involves interesting notation — especially when you add pointers to the mix.
Continue reading
Extremely Buffered Output
A few weeks back, I wrote a post on the fflush() function, which immediately relieves an output buffer, releasing its contents. The mirror opposite of this function might be another output control function, setbuf().
Continue reading
Rotate the Grid – Solution
The challenge for this month’s Exercise is to fill a grid with random letters, a to z, then rotate that grid on its side, counterclockwise, and display the results. Such fun.
Continue reading
The Teeniest of Tiniest
It took me a while to figure out the significance of the nextafter() function. Though I understand what it does now, I still can’t figure out how it’s useful, though I assume it has a valid purpose otherwise it wouldn’t be in the standard library.
Continue reading