Tiny C Projects

Book description

Learn the big skills of C programming by creating bite-size projects! Work your way through these 15 fun and interesting tiny challenges to master essential C techniques you’ll use in full-size applications.

In Tiny C Projects you will learn how to:

  • Create libraries of functions for handy use and re-use
  • Process input through an I/O filter to generate customized output
  • Use recursion to explore a directory tree and find duplicate files
  • Develop AI for playing simple games
  • Explore programming capabilities beyond the standard C library functions
  • Evaluate and grow the potential of your programs
  • Improve code to better serve users

Tiny C Projects is an engaging collection of 15 small programming challenges! This fun read develops your C abilities with lighthearted games like tic-tac-toe, utilities like a useful calendar, and thought-provoking exercises like encoding and cyphers. Jokes and lighthearted humor make even complex ideas fun to learn. Each project is small enough to complete in a weekend, and encourages you to evolve your code, add new functions, and explore the full capabilities of C.

About the Technology
The best way to gain programming skills is through hands-on projects—this book offers 15 of them. C is required knowledge for systems engineers, game developers, and roboticists, and you can start writing your own C programs today. Carefully selected projects cover all the core coding skills, including storing and modifying text, reading and writing files, searching your computer’s directory system, and much more.

About the Book
Tiny C Projects teaches C gradually, from project to project. Covering a variety of interesting cases, from timesaving tools, simple games, directory utilities, and more, each program you write starts out simple and gets more interesting as you add features. Watch your tiny projects grow into real applications and improve your C skills, step by step.

What's Inside
  • Caesar cipher solver: Use an I/O filter to generate customized output
  • Duplicate file finder: Use recursion to explore a directory tree
  • Daily greetings: Writing the moon phase algorithm
  • Lotto pics: Working with random numbers

And 11 more fun projects!

About the Reader
For C programmers of all skill levels.

About the Author
Dan Gookin has over 30 years of experience writing about complex topics. His most famous work is DOS For Dummies, which established the entire For Dummies brand.

Quotes
A ‘learning by playing’ approach to C! For me, it was a joyful return to the roots.
- Maciej Jurkowski, Grupa Pracuj

Dan blends the serious and amusing parts of C into a comfortable, gradual ladder of knowledge. No one else can write a book like this.
- Joe Tingsanchali, Sonar

I highly recommend to all of my colleagues who need to speed up slow Python code.
- Marco Carnini, Features Analytics

Excellent for anyone who wants to learn or relearn C. Highly recommended.
- Nathan McKinley-Pace, George Mason University

If you’ve never worked with C, or it’s been a long time since you have, this is an excellent book.
- Chris Kolosiwsky, Globality

Table of contents

  1. Tiny C Projects
  2. Copyright
  3. contents
  4. front matter
    1. preface
    2. Is C programming still relevant?
    3. Why did I write this book?
    4. acknowledgments
    5. about this book
      1. Who should read this book?
      2. How this book is organized: A road map
      3. Software/hardware requirements
      4. Online resources
      5. About the code
      6. liveBook discussion forum
    6. about the author
    7. about the cover illustration
  5. 1 Configuration and setup
    1. 1.1 The C development cycle
      1. 1.1.1 Editing source code
      2. 1.1.2 Compiling, linking, building
    2. 1.2 The integrated development environment (IDE)
      1. 1.2.1 Choosing an IDE
      2. 1.2.2 Using Code::Blocks
      3. 1.2.3 Using XCode
    3. 1.3 Command-line compiling
      1. 1.3.1 Accessing the terminal window
      2. 1.3.2 Reviewing basic shell commands
      3. 1.3.3 Exploring text screen editors
      4. 1.3.4 Using a GUI editor
      5. 1.3.5 Compiling and running
    4. 1.4 Libraries and compiler options
      1. 1.4.1 Linking libraries and setting other options in an IDE
      2. 1.4.2 Using command-line compiler options
    5. 1.5 Quiz
  6. 2 Daily greetings
    1. 2.1 The shell starts
      1. 2.1.1 Understanding how the shell fits in
      2. 2.1.2 Exploring various shell startup scripts
      3. 2.1.3 Editing the shell startup script
    2. 2.2 A simple greeting
      1. 2.2.1 Coding a greeting
      2. 2.2.2 Adding a name as an argument
    3. 2.3 The time of day
      1. 2.3.1 Obtaining the current time
      2. 2.3.2 Mixing in the general time of day
      3. 2.3.3 Adding specific time info
    4. 2.4 The current moon phase
      1. 2.4.1 Observing moon phases
      2. 2.4.2 Writing the moon phase algorithm
      3. 2.4.3 Adding the moon phase to your greeting
    5. 2.5 A pithy saying
      1. 2.5.1 Creating a pithy phrase repository
      2. 2.5.2 Randomly reading a pithy phrase
      3. 2.5.3 Adding the phrase to your greeting code
  7. 3 NATO output
    1. 3.1 The NATO alphabet
    2. 3.2 The NATO translator program
      1. 3.2.1 Writing the NATO translator
      2. 3.2.2 Reading and converting a file
    3. 3.3 From NATO to English
      1. 3.3.1 Converting NATO input to character output
      2. 3.3.2 Reading NATO input from a file
  8. 4 Caesarean cipher
    1. 4.1 I/O filters
      1. 4.1.1 Understanding stream I/O
      2. 4.1.2 Writing a simple filter
      3. 4.1.3 Working a filter at the command prompt
    2. 4.2 On the front lines with Caesar
      1. 4.2.1 Rotating 13 characters
      2. 4.2.2 Devising a more Caesarean cipher
    3. 4.3 Deep into filter madness
      1. 4.3.1 Building the hex output filter
      2. 4.3.2 Creating a NATO filter
      3. 4.3.3 Filtering words
  9. 5 Encoding and decoding
    1. 5.1 The concept of plain text
      1. 5.1.1 Understanding ASCII
      2. 5.1.2 Exploring the control codes
      3. 5.1.3 Generating noncharacter output
      4. 5.1.4 Playing with ASCII conversion tricks
    2. 5.2 The hex encoder/decoder
      1. 5.2.1 Writing a simple hex encoder/decoder
      2. 5.2.2 Coding a better hex encoder/decoder
      3. 5.2.3 Adding a wee bit of error-checking
    3. 5.3 URL encoding
      1. 5.3.1 Knowing all the URL encoding rules
      2. 5.3.2 Writing a URL encoder
      3. 5.3.3 Creating a URL decoder
  10. 6 Password generators
    1. 6.1 Password strategies
      1. 6.1.1 Avoiding basic and useless passwords
      2. 6.1.2 Adding password complexity
      3. 6.1.3 Applying the word strategy
    2. 6.2 The complex password jumble
      1. 6.2.1 Building a silly random password program
      2. 6.2.2 Adding conditions to the password program
      3. 6.2.3 Improving upon the password
    3. 6.3 Words in passwords
      1. 6.3.1 Generating random words, Mad Libs style
      2. 6.3.2 Building a random word password generator
  11. 7 String utilities
    1. 7.1 Strings in C
      1. 7.1.1 Understanding the string
      2. 7.1.2 Measuring a string
      3. 7.1.3 Reviewing C string functions
      4. 7.1.4 Returning versus modifying directly
    2. 7.2 String functions galore
      1. 7.2.1 Changing case
      2. 7.2.2 Reversing a string
      3. 7.2.3 Trimming a string
      4. 7.2.4 Splitting a string
      5. 7.2.5 Inserting one string into another
      6. 7.2.6 Counting words in a string
      7. 7.2.7 Converting tabs to spaces
    3. 7.3 A string library
      1. 7.3.1 Writing the library source and header file
      2. 7.3.2 Creating a library
      3. 7.3.3 Using the string library
    4. 7.4 A kinda OOP approach
      1. 7.4.1 Adding a function to a structure
      2. 7.4.2 Creating a string “object”
  12. 8 Unicode and wide characters
    1. 8.1 Text representation in computers
      1. 8.1.1 Reviewing early text formats
      2. 8.1.2 Evolving into ASCII text and code pages
      3. 8.1.3 Diving into Unicode
    2. 8.2 Wide character programming
      1. 8.2.1 Setting the locale
      2. 8.2.2 Exploring character types
      3. 8.2.3 Generating wide character output
      4. 8.2.4 Receiving wide character input
      5. 8.2.5 Working with wide characters in files
  13. 9 Hex dumper
    1. 9.1 Bytes and data
      1. 9.1.1 Reviewing storage units and size mayhem
      2. 9.1.2 Outputting byte values
      3. 9.1.3 Dumping data
    2. 9.2 Dump that file!
      1. 9.2.1 Reading file data
      2. 9.2.2 Fixing uneven output
    3. 9.3 Command-line options
      1. 9.3.1 Using the getopt() function
      2. 9.3.2 Updating the dumpfile program code
      3. 9.3.3 Setting abbreviated output
      4. 9.3.4 Activating octal output
  14. 10 Directory tree
    1. 10.1 The filesystem
    2. 10.2 File and directory details
      1. 10.2.1 Gathering file info
      2. 10.2.2 Exploring file type and permissions
      3. 10.2.3 Reading a directory
    3. 10.3 Subdirectory exploration
      1. 10.3.1 Using directory exploration tools
      2. 10.3.2 Diving into a subdirectory
      3. 10.3.3 Mining deeper with recursion
    4. 10.4 A directory tree
      1. 10.4.1 Pulling out the directory name
      2. 10.4.2 Monitoring directory depth
  15. 11 File finder
    1. 11.1 The great file hunt
    2. 11.2 A file finder
      1. 11.2.1 Coding the Find File utility
      2. 11.2.2 Understanding the glob
      3. 11.2.3 Using wildcards to find files
    3. 11.3 The duplicate file finder
      1. 11.3.1 Building a file list
      2. 11.3.2 Locating the duplicates
  16. 12 Holiday detector
    1. 12.1 The operating system wants its vig
      1. 12.1.1 Understanding exit status versus the termination status
      2. 12.1.2 Setting a return value
      3. 12.1.3 Interpreting the return value
      4. 12.1.4 Using the preset return values
    2. 12.2 All about today
      1. 12.2.1 Getting today’s date
      2. 12.2.2 Obtaining any old date
    3. 12.3 Happy holidays
      1. 12.3.1 Reviewing holidays in the United States
      2. 12.3.2 Discovering holidays in the UK
    4. 12.4 Is today a holiday?
      1. 12.4.1 Reporting regular date holidays
      2. 12.4.2 Dealing with irregular holidays
      3. 12.4.3 Calculating Easter
      4. 12.4.4 Running the date gauntlet
  17. 13 Calendar
    1. 13.1 The calendar program
    2. 13.2 Good dates to know
      1. 13.2.1 Creating constants and enumerating dates
      2. 13.2.2 Finding the day of the week
      3. 13.2.3 Calculating the first day of the month
      4. 13.2.4 Identifying leap years
      5. 13.2.5 Getting the time zone correct
    3. 13.3 Calendar utilities
      1. 13.3.1 Generating a week
      2. 13.3.2 Showing a month
      3. 13.3.3 Displaying a full year
      4. 13.3.4 Putting the full year into a grid
    4. 13.4 A calendar in color
      1. 13.4.1 Understanding terminal colors
      2. 13.4.2 Generating a tight-but-colorful calendar
      3. 13.4.3 Coloring holidays
  18. 14 Lotto picks
    1. 14.1 A tax for those who are bad at math
      1. 14.1.1 Playing the lottery
      2. 14.1.2 Understanding the odds
      3. 14.1.3 Programming the odds
    2. 14.2 Here are your winning numbers
      1. 14.2.1 Generating random values
      2. 14.2.2 Drawing lotto balls
      3. 14.2.3 Avoiding repeated numbers, another approach
    3. 14.3 Never tell me the odds
      1. 14.3.1 Creating the lotto() function
      2. 14.3.2 Matching lottery picks
      3. 14.3.3 Testing the odds
  19. 15 Tic-tac-toe
    1. 15.1 A silly kids’ game
      1. 15.1.1 Playing tic-tac-toe
      2. 15.1.2 Approaching the game mathematically
    2. 15.2 The basic game
      1. 15.2.1 Creating the game grid
      2. 15.2.2 Adding game play
      3. 15.2.3 Limiting the input to free squares
      4. 15.2.4 Determining the winner
    3. 15.3 The computer plays
      1. 15.3.1 Choosing the number of players
      2. 15.3.2 Coding a dumb opponent
      3. 15.3.3 Adding some intelligence
  20. index

Product information

  • Title: Tiny C Projects
  • Author(s): Dan Gookin
  • Release date: December 2022
  • Publisher(s): Manning Publications
  • ISBN: 9781633439825