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: Solution

Post navigation

← Older posts
Newer posts →

Increasing Brightness – Solution

Posted on March 8, 2018 by dgookin
Reply

The challenge for this month’s Exercise is to fill a cup without overflowing it. That cup is an unsigned char value, which goes only to 255 maximum. If your goal is increase the value of an unsigned char variable by 10 percent, any value over 255 - (255/10), or 220, must be set to 255.
Continue reading →

Posted in Solution | Leave a reply

Oscillation – Solution

Posted on February 8, 2018 by dgookin
5

For my solution to this month’s Oscillation Exercise I created a toggle variable. This variable switches between 1 and -1. It sets the direction for the cascading values.
Continue reading →

Posted in Solution | 5 Replies

Swapping Strings – Solution

Posted on January 8, 2018 by dgookin
Reply

This month’s Exercise involves swapping elements between two string arrays. A number of solutions exist (as always), but because the “strings” are really pointers, the solution can be very specific. Yes, you just might have to use that dratted ** notation. Brace yourselves.
Continue reading →

Posted in Solution | Leave a reply

Swapping Arrays – Solution

Posted on December 8, 2017 by dgookin
2

The two functions required from this month’s Exercise are show_arrays() and swap_arrays(). They’re not that difficult to code, meaning that you don’t need to use the dratted ** notation or perform any special tricks. Here’s how I solved the problem:
Continue reading →

Posted in Solution | 2 Replies

Filename Extractor – Solution

Posted on November 8, 2017 by dgookin
4

When I see a problem such as finding a filename in a pathname, one of the first things I think of are regular expressions. For this month’s Exercise, however, that’s not the solution I coded.
Continue reading →

Posted in Solution | 4 Replies

Right String – Solution

Posted on October 8, 2017 by dgookin
Reply

For this month’s Exercise, I offer both a string function solution as well as a solution that uses pointers. As you can guess, I thought of the string method first, which is where most programmers would run to avoid the dratted topic of pointers.
Continue reading →

Posted in Solution | Leave a reply

The URL Decoding Filter – Solution

Posted on September 8, 2017 by dgookin
Reply

Unwinding percent-encoding involves three steps:

  1. Pass-through the unchanged characters.
  2. Change + back into a space.
  3. Decode the percent strings, which is the most involved process.

Continue reading →

Posted in Solution | Leave a reply

The URL Encoding Filter – Solution

Posted on August 8, 2017 by dgookin
Reply

A URL filter isn’t that difficult to code, once you know the rules. I’m sure you can concoct something clever or obfuscated in the C language, but I chose to use a clutch of if/else if/else statements to process input and generate output.
Continue reading →

Posted in Solution | Leave a reply

Change Due – Solution

Posted on July 8, 2017 by dgookin
Reply

I confess, the solution to this month’s Exercise was frustrating. Several times, I thought to abandon the premise and focus on the main problem, which is how to create a random price, such as $5.32, without that floating-point value really being 5.3187321.
Continue reading →

Posted in Solution | Leave a reply

The Perfect Shuffle – Solution

Posted on June 8, 2017 by dgookin
Reply

A perfect shuffle splits a deck of cards in two. The second half is folded evenly into the first half, so that every other card comes from the first and last half of the deck, respectively. This type of shuffle is practically impossible in real life, but for a computer simulation it’s not that difficult.
Continue reading →

Posted in Solution | Leave a reply

Post navigation

← Older posts
Newer posts →

Recent Posts

  • The Ever-Expanding Pointer Array
  • Heron’s Formula – Solution
  • Coding a Better stringcopy() Function
  • Heron’s Formula
  • Copying Strings

Recent Comments

  • dgookin on Heron’s Formula
  • Chris Webb on Heron’s Formula
  • dgookin on Heron’s Formula
  • Chris Webb on Heron’s Formula
  • dgookin on Finding Those Pesky Null Characters!

Meta

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

Copyright © 1997-2025 by QPBC.
All rights reserved

Proudly powered by WordPress