ebook img

Beginning Programming with C For Dummies PDF

459 Pages·2014·34.941 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Beginning Programming with C For Dummies

Beginning Programming with C Beginning Programming with C by Dan Gookin Beginning Programming with C For Dummies® Published by John Wiley & Sons, Inc. 111 River Street Hoboken, NJ 07030-5774 www.wiley.com Copyright © 2014 by John Wiley & Sons, Inc., Hoboken, New Jersey Published by John Wiley & Sons, Inc., Hoboken, New Jersey Published simultaneously in Canada No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permit- ted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions. Trademarks: Wiley, the Wiley logo, For Dummies, the Dummies Man logo, A Reference for the Rest of Us!, The Dummies Way, Dummies Daily, The Fun and Easy Way, Dummies.com, Making Everything Easier, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates in the United States and other countries, and may not be used without written permission. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc., is not associated with any product or vendor mentioned in this book. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ. For general information on our other products and services, please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002. For technical support, please visit www.wiley.com/techsupport. Wiley also publishes its books in a variety of electronic formats and by print-on-demand. Not all content that is available in standard print versions of this book may appear or be packaged in all book formats. If you have purchased a version of this book that did not include media that is referenced by or accompanies a standard print version, you may request this media by visiting http://booksupport.wiley.com. For more information about Wiley products, visit us at www.wiley.com. Library of Congress Control Number: 2013948031 ISBN 978-1-118-73763-7 (pbk); ISBN 978-1-118-73765-1 (ebk); ISBN 978-1-118-73762-0 (ebk) Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 Contents at a Glance Introduction ................................................................ 1 Part I: Getting Started with C Programming................... 7 Chapter 1: A Quick Start for the Impatient .....................................................................9 Chapter 2: The Programming Thing ..............................................................................21 Chapter 3: Anatomy of C .................................................................................................31 Part II: C Programming 101 ....................................... 45 Chapter 4: Trials and Errors ...........................................................................................47 Chapter 5: Values and Constants ...................................................................................59 Chapter 6: A Place to Put Stuff .......................................................................................71 Chapter 7: Input and Output ..........................................................................................83 Chapter 8: Decision Making ............................................................................................97 Chapter 9: Loops, Loops, Loops ..................................................................................113 Chapter 10: Fun with Functions ...................................................................................129 Part III: Build Upon What You Know ......................... 143 Chapter 11: The Unavoidable Math Chapter ..............................................................145 Chapter 12: Give Me Arrays ..........................................................................................163 Chapter 13: Fun with Text.............................................................................................181 Chapter 14: Structures, the Multivariable ..................................................................199 Chapter 15: Life at the Command Prompt ..................................................................209 Chapter 16: Variable Nonsense ....................................................................................219 Chapter 17: Binary Mania .............................................................................................231 Part IV: The Advanced Part ...................................... 249 Chapter 18: Introduction to Pointers ..........................................................................251 Chapter 19: Deep into Pointer Land ............................................................................267 Chapter 20: Linked Lists ...............................................................................................287 Chapter 21: It’s About Time ..........................................................................................307 Part V: And the Rest of It ......................................... 315 Chapter 22: Permanent Storage Functions .................................................................317 Chapter 23: File Management .......................................................................................335 Chapter 24: Beyond Mere Mortal Projects .................................................................345 Chapter 25: Out, Bugs! ...................................................................................................355 Part VI: The Part of Tens .......................................... 367 Chapter 26: Ten Common Boo-Boos ...........................................................................369 Chapter 27: Ten Reminders and Suggestions .............................................................377 Afterword ................................................................ 385 Appendix A: ASCII Codes .......................................... 387 Appendix B: Keywords ............................................. 393 Appendix C: Operators .............................................. 395 Appendix D: Variable Types ...................................... 397 Appendix E: Escape Sequences .................................. 399 Appendix F: Conversion Characters ............................ 401 Appendix G: Order of Precedence .............................. 403 Index ...................................................................... 405 Table of Contents Introduction ................................................................. 1 Is the C Language Relevant? ...........................................................................1 The C Programming For Dummies Approach ..............................................2 How This Book Works .....................................................................................2 Icons Used in This Book .................................................................................4 Parting Thoughts .............................................................................................4 Part I: Getting Started with C Programming ................... 7 Chapter 1: A Quick Start for the Impatient . . . . . . . . . . . . . . . . . . . . . . . . . 9 What You Need in Order to Program ............................................................9 Obtaining programming tools ..............................................................9 Acquiring an Integrated Development Environment (IDE).............10 Behold the Code::Blocks IDE ........................................................................10 Installing Code::Blocks ........................................................................10 Touring the Code::Blocks workspace ................................................12 Your First Project ..........................................................................................14 Creating a new project ........................................................................14 Examining the source code ................................................................16 Building and running the project .......................................................18 Saving and closing ...............................................................................19 Chapter 2: The Programming Thing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 The History of Programming ........................................................................21 Reviewing early programming history ..............................................22 Introducing the C language .................................................................22 The Programming Process ...........................................................................23 Understanding programming .............................................................23 Writing source code ............................................................................24 Compiling to object code ....................................................................26 Linking in the C library ........................................................................27 Running and testing .............................................................................28 viii Beginning Programming with C For Dummies Chapter 3: Anatomy of C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Parts of the C Language ................................................................................31 Keywords ..............................................................................................32 Functions ..............................................................................................33 Operators ..............................................................................................34 Variables and values ...........................................................................35 Statements and structure ...................................................................35 Comments .............................................................................................36 Behold the Typical C Program .....................................................................38 Understanding C program structure .................................................39 Setting the main() function ................................................................39 Returning something to the operating system ................................40 Adding a function .................................................................................41 Part II: C Programming 101 ........................................ 45 Chapter 4: Trials and Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Display Stuff on the Screen ..........................................................................47 Displaying a humorous message .......................................................47 Introducing the puts() function.........................................................48 Adding more text .................................................................................49 Commenting out a statement .............................................................50 Goofing up on purpose ........................................................................51 More Display Nonsense ................................................................................53 Displaying text with printf() ..............................................................53 Introducing the printf() function.......................................................54 Understanding the newline .................................................................55 Employing escape sequences.............................................................55 Goofing up on purpose again .............................................................57 Chapter 5: Values and Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 A Venue for Various Values ..........................................................................59 Understanding values ..........................................................................60 Displaying values with printf() ..........................................................60 Minding the extra zeroes ....................................................................62 The Computer Does the Math ......................................................................63 Doing simple arithmetic ......................................................................63 Reviewing the float-integer thing .......................................................65 Always the Same ............................................................................................66 Using the same value over and over .................................................66 Introducing constants .........................................................................67 Putting constants to use .....................................................................68

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.