Skip to primary content
Skip to secondary content

C For Dummies Blog

Main menu

  • C For Dummies (home)
  • History
  • Series
  • Supplemental
  • Blog Miscellany

Category Archives: Lesson

Post navigation

← Older posts
Newer posts →

Un-Buffering Output

Posted on July 20, 2019 by dgookin
6

Last year, I wrote about using the standard error device stderr to generate output that can’t be redirected. This technique is often used to send error messages to the console, though I noted how these messages may show up out of sync with standard output. This situation can be resolved, providing you know how to flush the stderr device buffer.
Continue reading →

Posted in Lesson | 6 Replies

Putting strtol() to the Test

Posted on July 13, 2019 by dgookin
4

Stop using the atoi() function! Yes, it’s a golden oldie, often my go-to function for converting strings to integers, but it’s weak. The strtol() function, on the other hand, not only converts strings to integers, it can validate input as well.
Continue reading →

Posted in Lesson | 4 Replies

Peculiarities of the strtol() Function

Posted on July 6, 2019 by dgookin
Reply

Imagine my disappointment to learn that the atoi() function, one of the first I learned in C, is actually a macro. I’m horrified. As much as I treasure converting strings to integers, I shall survive this life-changing discovery.
Continue reading →

Posted in Lesson | Leave a reply

Exponentiation

Posted on June 29, 2019 by dgookin
2

The C language lacks an exponentiation operator, which would raise a base value to a certain power. For example: 2^8, which in some programming languages is an expression to raise 2 to the 8th power. Instead, C uses the pow() function.
Continue reading →

Posted in Lesson | 2 Replies

The Perils of strncpy()

Posted on June 22, 2019 by dgookin
2

Always be careful when manipulating strings! Tack on that null character, '\0', at the end of a string! And don’t worry about the C language string functions: They perform this important feature for you. But do they all?
Continue reading →

Posted in Lesson | 2 Replies

To Read a Chunk a Data

Posted on June 15, 2019 by dgookin
2

Say you must read 2048 bytes from a file. Which of the following fread() statements works for you: A, B, both, or neither?

A. c = fread( buffer, 2048, 1, fh);

B. c = fread( buffer, 1, 2048, fh);
Continue reading →

Posted in Lesson | 2 Replies

Old Habits Die Hard

Posted on June 8, 2019 by dgookin
Reply

Like doing anything for a long period of time, I find myself often using the same approach to solving a programming puzzle. It’s habit. It’s tradition. And it often hinders my insight into the language.
Continue reading →

Posted in Lesson | Leave a reply

Slicing Words from a String

Posted on June 1, 2019 by dgookin
Reply

The fall-through effect of the switch-case structure can be extremely useful, as demonstrated in last week’s Lesson. For slicing words from a string, you can easily match multiple word separators, saving you from coding complex statements or weirdo if-else structures. But a problem arises when multiple word separators appear.
Continue reading →

Posted in Lesson | Leave a reply

Falling Through a Switch-Case Structure

Posted on May 25, 2019 by dgookin
Reply

C language keywords often used in a switch-case structure are switch, case, default, and break. Only switch and case are required. You can omit the default condition. And the break keyword is used to avoid execution falling through the structure, yet sometimes that may be a useful effect.
Continue reading →

Posted in Lesson | Leave a reply

Switch-Case Execution

Posted on May 18, 2019 by dgookin
Reply

The switch-case structure is the most complex decision tool in the C language. Yes, the ternary operator is more cryptic, but a proper switch-case structure involves more keywords: switch, case, default, and break. The break keyword is what I feel makes the structure most interesting.
Continue reading →

Posted in Lesson | Leave a reply

Post navigation

← Older posts
Newer posts →

Recent Posts

  • Cooked or Raw?
  • Is It a “Real” Triangle? – Solution
  • Getting and Setting the File Position Indicator
  • Is It a “Real” Triangle?
  • A Colorful Hexdump

Recent Comments

  • dgookin on Is It a “Real” Triangle? – Solution
  • Chris Webb on Is It a “Real” Triangle? – Solution
  • dgookin on A Colorful Hexdump
  • Chris Webb on A Colorful Hexdump
  • dgookin on Code Page 437

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Copyright © 1997-2026 by QPBC.
All rights reserved

Proudly powered by WordPress