About This eBook
ePUB is an open, industry-standard format for eBooks. However, support of ePUB and its many features varies across reading devices and applications. Use your device or app settings to customize the presentation to your liking. Settings that you can customize often include font, font size, single or double column, landscape or portrait mode, and figures that you can click or tap to enlarge. For additional information about the settings and features on your reading device or app, visit the device manufacturers Web site.
Many titles include programming code or configuration examples. To optimize the presentation of these elements, view the eBook in single-column, landscape mode and adjust the font size to the smallest setting. In addition to presenting code and configurations in the reflowable text format, we have included images of the code that mimic the presentation found in the print book; therefore, where the reflowable format may compromise the presentation of the code listing, you will see a Click here to view code image link. Click the link to view the print-fidelity code image. To return to the previous page viewed, click the Back button on your device or app.
Programming in C
Fourth Edition
Stephen G. Kochan
Upper Saddle River, NJ Boston Indianapolis San Francisco
New York Toronto Montreal London Munich Paris Madrid
Cape Town Sydney Tokyo Singapore Mexico City
Programming in C, Fourth Edition
Copyright 2015 by Pearson Education, Inc.
All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein.
ISBN-13: 978-0-321-77641-9
ISBN-10: 0-321-77641-0
Library of Congress Control Number: 2014944082
Printed in the United States of America
First Printing: August 2014
Acquisitions Editor
Mark Taber
Managing Editor
Sandra Schroeder
Project Editor
Mandie Frank
Copy Editor
Charlotte Kughen
Indexer
Brad Herriman
Proofreader
Debbie Williams
Technical Editor
Siddhartha Singh
Editorial Assistant
Vanessa Evans
Designer
Chuti Prasertsith
Compositor
Mary Sudul
Trademarks
All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. The publisher cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark.
Warning and Disclaimer
Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an as is basis. The author and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book.
Special Sales
For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at or (800) 382-3419.
For government sales inquiries, please contact .
For questions about sales outside the U.S., please contact .
Developers Library
ESSENTIAL REFERENCES FOR PROGRAMMING PROFESSIONALS
Developers Library books are designed to provide practicing programmers with unique, high-quality references and tutorials on the programming languages and technologies they use in their daily work.
All books in the Developers Library are written by expert technology practitioners who are especially skilled at organizing and presenting information in a way thats useful for other programmers.
Key titles include some of the best, most widely acclaimed books within their topic areas:
Programming in Objective-C
Stephen G. Kochan
ISBN 978-0-321-96760-2
MySQL
Paul DuBois
ISBN-13: 978-0-321-83387-7
Linux Kernel Development
Robert Love
ISBN-13: 978-0-672-32946-3
Python Essential Reference
David Beazley
ISBN-13: 978-0-672-32978-4
PostgreSQL
Korry Douglas
ISBN-13: 978-0-672-32756-8
C++ Primer Plus
Stephen Prata
ISBN-13: 978-0-321-77640-2
Developers Library books are available in print and in electronic formats at most retail and online bookstores, as well as by subscription from Safari Books Online at safari.informit.com
Developers Library
informit.com/devlibrary
For my mother and father
Contents at a Glance
Table of Contents
About the Author
Stephen G. Kochan has been developing software with the C programming language for more than 30 years. He is the author of several best-selling titles on the C language, including Programming in C, Programming in Objective-C, and Topics in C Programming. He has also written extensively on Unix and is the author or coauthor of Exploring the Unix System and Unix Shell Programming.
Contributing Author, Fourth Edition
Dean Miller is a writer and editor with more than 20 years of experience in both the publishing and licensed consumer products businesses. He is coauthor of the most recent editions of Sams Teach Yourself C in One Hour a Day, and Sams Teach Yourself Beginning Programming in 24 Hours.
Acknowledgments
I wish to thank the following people for their help in the preparation of various versions of this text: Douglas McCormick, Jim Scharf, Henry Tabickman, Dick Fritz, Steve Levy, Tony Ianinno, and Ken Brown. I also want to thank Henry Mullish of New York University for teaching me so much about writing and for getting me started in the publishing business.
At Pearson, Id like to thank Mark Taber and my project editor Mandie Frank. Thanks also to my copy editor, Charlotte Kughen, and my technical editor, Siddhartha Singh. Finally, Id like to thank all the other people from Pearson who were involved on this project, even if I did not work with them directly.
We Want to Hear from You!
As the reader of this book, you are our most important critic and commentator. We value your opinion and want to know what were doing right, what we could do better, what areas youd like to see us publish in, and any other words of wisdom youre willing to pass our way.
We welcome your comments. You can email or write directly to let us know what you did or didnt like about this bookas well as what we can do to make our books better.