Tiny C Projects

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

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.

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

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.

Table of Contents
1 Configuration and setup
2 Daily greetings
3 NATO output
4 Caesarean cipher
5 Encoding and decoding
6 Password generators
7 String utilities
8 Unicode and wide characters
9 Hex dumper
10 Directory tree
11 File finder
12 Holiday detector
13 Calendar
14 Lotto picks
15 Tic-tac-toe

Author(s): Dan Gookin
Edition: 1
Publisher: Manning
Year: 2022

Language: English
Pages: 384
City: New York
Tags: C Programming Language; C Development; Development Techniques; I/O Processing; Recursion; AI Development; Standard C Library; C Hands-On Projects; Core Coding Skills

front matter

preface

acknowledgments

about this book

about the author

about the cover illustration

1 Configuration and setup

1.1 The C development cycle

Editing source code

Compiling, linking, building

1.2 The integrated development environment (IDE)

Choosing an IDE

Using Code::Blocks

Using XCode

1.3 Command-line compiling

Accessing the terminal window

Reviewing basic shell commands

Exploring text screen editors

Using a GUI editor

Compiling and running

1.4 Libraries and compiler options

Linking libraries and setting other options in an IDE

Using command-line compiler options

1.5 Quiz

2 Daily greetings

2.1 The shell starts

Understanding how the shell fits in

Exploring various shell startup scripts

Editing the shell startup script

2.2 A simple greeting

Coding a greeting

Adding a name as an argument

2.3 The time of day

Obtaining the current time

Mixing in the general time of day

Adding specific time info

2.4 The current moon phase

Observing moon phases

Writing the moon phase algorithm

Adding the moon phase to your greeting

2.5 A pithy saying

Creating a pithy phrase repository

Randomly reading a pithy phrase

Adding the phrase to your greeting code

3 NATO output

3.1 The NATO alphabet

3.2 The NATO translator program

Writing the NATO translator

Reading and converting a file

3.3 From NATO to English

Converting NATO input to character output

Reading NATO input from a file

4 Caesarean cipher

4.1 I/O filters

Understanding stream I/O

Writing a simple filter

Working a filter at the command prompt

4.2 On the front lines with Caesar

Rotating 13 characters

Devising a more Caesarean cipher

4.3 Deep into filter madness

Building the hex output filter

Creating a NATO filter

Filtering words

5 Encoding and decoding

5.1 The concept of plain text

Understanding ASCII

Exploring the control codes

Generating noncharacter output

Playing with ASCII conversion tricks

5.2 The hex encoder/decoder

Writing a simple hex encoder/decoder

Coding a better hex encoder/decoder

Adding a wee bit of error-checking

5.3 URL encoding

Knowing all the URL encoding rules

Writing a URL encoder

Creating a URL decoder

6 Password generators

6.1 Password strategies

Avoiding basic and useless passwords

Adding password complexity

Applying the word strategy

6.2 The complex password jumble

Building a silly random password program

Adding conditions to the password program

Improving upon the password

6.3 Words in passwords

Generating random words, Mad Libs style

Building a random word password generator

7 String utilities

7.1 Strings in C

Understanding the string

Measuring a string

Reviewing C string functions

Returning versus modifying directly

7.2 String functions galore

Changing case

Reversing a string

Trimming a string

Splitting a string

Inserting one string into another

Counting words in a string

Converting tabs to spaces

7.3 A string library

Writing the library source and header file

Creating a library

Using the string library

7.4 A kinda OOP approach

Adding a function to a structure

Creating a string “object”

8 Unicode and wide characters

8.1 Text representation in computers

Reviewing early text formats

Evolving into ASCII text and code pages

Diving into Unicode

8.2 Wide character programming

Setting the locale

Exploring character types

Generating wide character output

Receiving wide character input

Working with wide characters in files

9 Hex dumper

9.1 Bytes and data

Reviewing storage units and size mayhem

Outputting byte values

Dumping data

9.2 Dump that file!

Reading file data

Fixing uneven output

9.3 Command-line options

Using the getopt() function

Updating the dumpfile program code

Setting abbreviated output

Activating octal output

10 Directory tree

10.1 The filesystem

10.2 File and directory details

Gathering file info

Exploring file type and permissions

Reading a directory

10.3 Subdirectory exploration

Using directory exploration tools

Diving into a subdirectory

Mining deeper with recursion

10.4 A directory tree

Pulling out the directory name

Monitoring directory depth

11 File finder

11.1 The great file hunt

11.2 A file finder

Coding the Find File utility

Understanding the glob

Using wildcards to find files

11.3 The duplicate file finder

Building a file list

Locating the duplicates

12 Holiday detector

12.1 The operating system wants its vig

Understanding exit status versus the termination status

Setting a return value

Interpreting the return value

Using the preset return values

12.2 All about today

Getting today’s date

Obtaining any old date

12.3 Happy holidays

Reviewing holidays in the United States

Discovering holidays in the UK

12.4 Is today a holiday?

Reporting regular date holidays

Dealing with irregular holidays

Calculating Easter

Running the date gauntlet

13 Calendar

13.1 The calendar program

13.2 Good dates to know

Creating constants and enumerating dates

Finding the day of the week

Calculating the first day of the month

Identifying leap years

Getting the time zone correct

13.3 Calendar utilities

Generating a week

Showing a month

Displaying a full year

Putting the full year into a grid

13.4 A calendar in color

Understanding terminal colors

Generating a tight-but-colorful calendar

Coloring holidays

14 Lotto picks

14.1 A tax for those who are bad at math

Playing the lottery

Understanding the odds

Programming the odds

14.2 Here are your winning numbers

Generating random values

Drawing lotto balls

Avoiding repeated numbers, another approach

14.3 Never tell me the odds

Creating the lotto() function

Matching lottery picks

Testing the odds

15 Tic-tac-toe

15.1 A silly kids’ game

Playing tic-tac-toe

Approaching the game mathematically

15.2 The basic game

Creating the game grid

Adding game play

Limiting the input to free squares

Determining the winner

15.3 The computer plays

Choosing the number of players

Coding a dumb opponent

Adding some intelligence

index