Considered a classic by an entire generation of Mac programmers, Dave Mark's Learn C on the Machas been updated for you to include Mac OS X Mountain Lion and the latest iOS considerations. Learn C on the Mac: For OS X and iOS, Second Edition is perfect for beginners learning to program. It includes contemporary OS X and iOSexamples! This book also does the following: Provides best practices for programming newbies Presents all the basics with a pragmatic, Mac OS X and iOS -flavored approach Includes updated source code which is fully compatible with latest Xcode What you'll learn Master C programming, the gateway to programming your Mac, iPhone or iPad Write apps for the contemporary Mac OS X interface, the cleanest user interface around Write apps for the modern iOS interface, one of the two most popular mobile platforms in the world Understand variables and how to design your own data structures Work with the file system Connect to data sources and the Internet How to handle error handling and much more Who this book is for
For anyone wanting to learn to program in Mac OS X and iOS, including developers new to the Mac and iPhone/iPad, developers new to C, or students entirely new to programming. Table of Contents Chapter 1: Go Get the Tools Chapter 2. Programming Basics Chapter 3: C Basics: Staements and Functions Chapter 4: C Basics: Variables and Operators Chapter 5: Debugging Chapter 6: Controlling Your Program's Flow Chapter 7: Pointers and Parameters Chapter 8: More Data Types Chapter 9: The Command Line Chapter 10: Designing Your Own Data Structures Chapter 11: Working with Files Chapter 12: Handling Errors Chapter 13: Advanced Topics Chapter 14: Where Do You Go from Here? Chapter 15: Answers to Exercises
Author(s): Dave Mark; James Bucanek
Edition: 2
Publisher: Apress
Year: 2012
Language: English
Pages: 508
Cover
Contents at a Glance
Contents
About the Authors
About the Technical Reviewer
Acknowledgments
Introduction
Chapter 1 Go Get the Tools!
Installing Xcode
How much is that IDE in the Window?
What’s a Registered Developer?
Getting the Projects
Using Xcode
Creating a New Xcode Project
The Workspace Window
Running a Project
Moving On
Chapter 2 Programming Basics
Programming
Some Alternatives to C
What About Objective-C, C#, C++, and Java?
What’s the Best Programming Language for the Mac or iOS Devices?
The Programming Process
Source Code
Compiling Your Source Code
Building Your Application
What’s Next?
Chapter 3 C Basics: Statements and Functions
C Statements
C Functions
Defining a Function
Syntax Errors and Algorithms
Calling a Function
Same Program, Two Functions
The Hello2 Project
The Hello2 Source Code
Running Hello2
Doing That Again, and Again, and Again
Generating Some Errors
Fixing the Problem
Getting Close
C is Case Sensitive
Exploring Xcode’s Built-In Manuals
Getting Help Quickly
What’s Next?
Chapter 4 C Basics: Variables and Operators
An Introduction to Variables
Working with Variables
Variable Names
The Size of a Type
Bytes and Bits
Going from 1 Byte to 2 Bytes
Operators
The +, -, ++, and -- Operators
The += and -= Operators
The *, /, %, *=, /=, and %= Operators
Using Parentheses
Operator Precedence
Sample Programs
Opening Operator.xcodeproj
Stepping Through the Operator Source Code
Opening Postfix.xcode
Stepping Through the Postfix Source Code
Sprucing Up Your Code
Source Code Spacing
Comment Your Code
The Curly Brace Controversy
What’s Next?
Chapter 5 Debugging
What’s a Debugger?
Controlling Execution
Setting Breakpoints
Stepping Over a Statement
Stepping Into a Function
Stepping Out of a Function
Full Speed Ahead
Examining Variables
How is a Debugger like an Iceberg?
What’s Next?
Chapter 6 Controlling Your Program’s Flow
Flow Control
The if Statement
Expressions
True Expressions
Comparative Operators
Logical Operators
TruthTester.xcodeproj
Compound Expressions
Statements
The Curly Braces
Where to Place the Semicolon
Two Common Pitfalls
The while Statement
The for Statement
LoopTester.xcodeproj
The do Statement
The switch Statement
A case with No Statements
The Mixed Blessing of Fall-Through
switch Wrap-Up
Breaks in Loops
The continue Statement
IsOdd.xcodeproj
Stepping Through the IsOdd Source Code
NextPrime.xcodeproj
Stepping Through the NextPrime Source Code
What’s Next?
Chapter 7 Pointers and Parameters
What Is a Pointer?
Why Use Pointers?
Checking Out of the Library
Pointer Basics
The Address of a Variable
The & Operator
Declaring a Pointer Variable
The * Operator
Function Parameters
Variable Scope
How Function Parameters Work
Parameters Are Temporary
The Difference Between Arguments and Parameters
Function Return Value
printf() Returns a Value
Multiple Return Statements
Returning Nothing at All
Putting it All Together
Using Pointers as Parameters
Factor.xcodeproj
Some Pointers on Pointers
Pass-By-Value vs. Pass-By-Reference
The NULL Pointer Value
The Dark Side of Pointers
Global and Static Variables
Global Variables
Adding Globals to Your Programs
Static Variables
What’s Next?
Chapter 8 More Data Types
Data Types Beyond Int
FloatSizer
The Integer Types
IntSizer.xcodeproj
The Long and Short of ints
The Best int for the Job
Semantic Types
Exact-Width Types
Integer vs. Floating Point
Working with Characters
The ASCII Character Set
ASCII.xcodeproj
Stepping Through the ASCII Source Code
Arrays
Why Use Arrays?
Dice.xcode
Stepping Through the Dice Source Code
Danger, Will Robinson!
The #define Directive
Using #defines in Your Code
Stepping Through the Preprocessor
The Advantages of Using #define Directives
Function-like #define Macros
Text Strings
A Text String in Memory
FullName.xcodeproj
Overflow.xcodeproj
What’s Next?
Chapter 9 The Command Line
Command Line Basics
Command Arguments
Learning More About Commands
Where Shell Commands Come From
Creating a Command-Line Tool
Command Arguments and main()
SeeArgs.xcodeproj
Deploying the Program
Using Paths
Current Directory and Relative Paths
Special Directory Names
The Home Directory Name
Installing a Command-Line Tool
Creating a Private bin Directory
Installing the Tool
Configuring the PATH Variable
Character Input
Pipes
Redirection
Namer.xcodeproj
Pointer Arithmetic
Comparing Pointers
Pointer Addition
Subtracting Pointers
WordCount.xcodeproj
Stepping Through the WordCount Source Code
Testing WordCount in the Shell
RomanNumeral.xcodeproj
main()
NumberToRomanNumeral()
One Last Word About the Command-Line Interface
What’s Next?
Chapter 10 Designing Your Own Data Structures
Bundling Data
Model A: Three Arrays
MultiArray.xcodeproj
Model B: The Structure Approach
StructSize.xcodeproj
Passing a struct As a Parameter
Passing a Copy of the struct
ParamAddress.xcodeproj
struct Arrays
Allocating Your Own Memory
Using malloc()
free()
Keeping Track of That Address!
Working with Linked Lists
Why Use Linked Lists?
Creating a Linked List
DVDTracker.xcodeproj
Stepping Through the DVDTracker Source Code
What’s Next?
Chapter 11 Working With Files
What Is a Data File?
File Basics
Understanding File Names
Opening and Closing a File
Reading a File
PrintFile.xcodeproj
Stepping Through the PrintFile Source Code
Writing Files
DVDFiler.xcodeproj
Fancier File Manipulation
The Update Modes
Random File Access
Using Random Access Functions
DinoEdit.xcodeproj
Text vs. Data Files
Working with Endians
Making RomanNumeral a Better Tool
Stepping Through RomanNumeral.xcodeproj
Putting RomanNumeral Through Its Paces
File System Objects
What’s Next?
Chapter 12 Handling Errors
Murphy’s Law
Rule #1: Never Assume
Assumptions About Variables
Check Ranges
Tolerate All Possible Values
Assert Your Assumptions
Rule #2: Stay Alert
Pay Attention to Return Values
errno
Rule #3: Have an Escape Plan
Follow the Success
Early Return
Skip Past Failure
Percolate Errors Up
Exit, Stage Left
The Long Jump
Rule #4: Anticipate Problems
Rule #5: Pick Your Battles
What’s Next?
Chapter 13 Advanced Topics
Type Conversion
Conversion Rules
Conversion Warnings
Typecasting
Typecasting Pointers
const Modifier
Creating Your Own Types
struct typedefs
Forward References
Enumerated Types
Unions
Why Use Unions?
Recursion
The Iterative Approach
A Recursive Approach
Function Pointers
The Remaining Operators
Getting More From The Libraries
Sorting with the Standard Library
Collections in Core Foundation
What’s Next?
Chapter 14 Where Do You Go from Here?
The Mac User Interface
Learning Objective-C
Learning Cocoa and Cocoa Touch
A Bit of OS X Code
A Quick iOS App
Just a Touch of Objective-C
Go Get ‘Em
Appendix: Answers to Exercises
Index
Numers and Symbols
A
B
C
D
E
F
G
H
I, J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X, Y
Z