C Programming The Definitive Beginner's Reference. -Harry H. Chaudhary. (IT Manager @ Anonymous International) Author Note: Every possible effort has been made to ensure that the information contained in this book is accurate, and the publisher or the Author can’t accept responsibility for any errors or omissions, however caused. All liability for loss, disappointment, negligence or other damage caused by the reliance of the Technical Programming or other information contained in this book, of in the event of bankruptcy or liquidation or cessation of trade of any company, individual; or firm mentioned, is hereby excluded. All other marks are property of their respective owners. The examples of companies, organizations, products, domain names, email addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, email address, logo, person, place, or event is intended or should be inferred. The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. This book expresses the author views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, and Publisher, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. Copyright © 2014 By Hariom Chaudhary. (Harry) Published By First MIT- Createspace Inc. O-D-Publishing, LLC USA. All rights reserved. This book or any portion thereof may not be reproduced or used in any manner whatsoever without the express written permission of the author Harry (Hariom Chaudhary) except for the use of brief quotations in a book review or scholarly journal. ISBN 13: 978-1500481001. ISBN-10: 1500481009. Marketing & Distribution By Amazon Inc. & Other 1500 worldwide Bookstores. Print Paperback Edition Available on Amazon.com and Digital PDF Edition Available on Google Books and Google Play and Lulu.com with Discount. For Publish this book in other language or request permission or license of this book work contact Author’s Assistance- [email protected] Dedication “This book is most dedicated to all those who make the daily sacrifices, Especially those who have made the ultimate sacrifice, to ensure our freedom & security.” You told me that everything will be okay in the end, You also told me that, if it’s not okay, it’s not the end. “I’ll search for you through 1000 worlds & 10000 lifetimes until I find you” About Author: Harry, H. Chaudhary is an Indian computer Programming and Bestselling Java Author and scientifically Hacking professional has a unique experience in the field of computers Programming, Hacking and Cyber Security. He has helped many Countries Governments and many multinational Software companies of around the globe to secure their networks and securities. He has authored several books on Various Computers Programming Languages and computer security & Hacking. He is basically known for his international bestselling Programming book “Core Java Professional.” He is technically graduate software engineer and Master. He is the leading authority on C Programming and C++ Programming as well as on Core Java and Data Structure and Algorithms. His acclaimed C and C++, C# & Java books. He has over 5 years of experience as a software methodologist. His teaching and research interests are in the areas of artificial intelligence, programming languages. He is living two lives. One life, He is a Computer program writer for a respectable software company. The other life is lived in computers, where he go by the hacker alias 'Harry" and are guilty of virtually every computer crime. Currently he is working as offline IT manager @ world famous community Anonymous international Community. Author side: You may have noticed something missing here: no impressive of credentials. I haven't been a professor at a Prestigious University for a quarter-century; neither am I a top executive at a Silicon Valley giant. In some ways, I'm a student of Technology, just like you are. And my experience over the years has shown me that many of the people who know the most about how technology works also have rather limited success in explaining what they know in a way that will allow me to understand it. My interests, and I believe my skills, lie not in being an expert, but an educator, in presenting complex information in a form that is sensible, digestible and fun to read my books. "What is real? How do you define real? If you're talking about what you can feel, what you can smell, what you can taste and see, then real is simply, electrical signals interpreted by your brain." ‘‘... I am just now beginning to discover the difficulty of expressing one’s ideas on paper. As long as it consists solely of description it is pretty easy; but where reasoning comes into play, to make a proper connection, a clearness & a moderate fluency, is to me, as I have said, a difficulty of which I had no idea ...’’ – Harry ∞ Inside Topics at a Glance ∞ S.No. Chapters Page 1. Preface – Page-6, || Introduction to C. 07 2. Elements of C Programming Language. 33 3. Control statements (conditions). 62 4. Control statements (Looping). 75 5. One dimensional Array. 107 6. Multi-Dimensional Array. 125 7. String (Character Array). 131 8. Your Brain on Functions. 141 9. Your Brain on Pointers. 173 10. Structure, Union, Enum, Bit Fields, Typedef. 197 11. Console Input and Output. 219 12. File Handling In C. 227 13. Miscellaneous Topics. 237 14. Storage Class. 247 15. Algorithms. 253 16. Unsolved Practical Problems. 257 17. PART-II-120+ Practical Code Chapter-Wise. 271 18. Creating & Inserting own functions in Liberary. 341 19. Graphics Programming In C. 345 20. Operating System Development –Intro. 349 21. C Programming Guidelines. 356 22. Common C Programming Errors. 367 23. Live Software Development Using C. 383-395 Preface: ∞ ∞ Essential C Programming Skills--Made Easy! L earn the all basics and advanced features of C programming in no time from Bestselling Programming Author Harry. H. Chaudhary. This Book, starts with the basics; I promise this book will make you 100% expert level champion of C Programming. Anyone can learn C Programming through this book at expert level. Engineering Students and fresh developers can also use this book. In software development section I explained live software project. As we all knows Author Harry is basically known for his “Easy Techniques-Explanations in Programming World - Learn with Fun Style !” To use this book does not require any previous programming experience. T his book covers common core syllabus for BCA, MCA, B.TECH, M.TECH, BS (CS), MS (CS), BSC-IT (CS), MSC-IT (CS), and Computer Science Professionals as well as for Hackers. This book contains 1000+ Live C Program’s code examples, and 500+ Lab Exercise & 200+ Brain Wash Topic-wise Code book and 20+ Live software Development Project’s. All what you need ! Isn’t it ? T his Book is very serious C Programming stuff: A complete introduction to C Language. You'll learn everything from the fundamentals to advanced topics. If you've read this book, you know what to expect a visually rich format designed for the way your brain works. If you haven't, you're in for a treat. You'll see why people say it's unlike any other C book you've ever read. L earning a new language is no easy. You might think the problem is your brain. It seems to have a mind of its own, a mind that doesn't always want to take in the dry, technical stuff you're forced to study. T he fact is your brain craves novelty. It's constantly searching, scanning, waiting for something unusual to happen. After all, that's the way it was built to help you stay alive. It takes all the routine, ordinary, dull stuff and filters it to the background so it won't interfere with your brain's real work--recording things that matter. How does your brain know what matters? CHAPTER ∞ 1 ∞ (Introduction To C) I ntroduction- Stuff you need to know about language levels – Programming languages have different levels, depending on how much they resemble human Languages. Programming languages that use common words and are relatively easy for most folks to read and study are called high level languages. The opposite of those are low-level languages, which are not easy to read or study. High-level languages include the popular BASIC programming language as well as other languages that just aren’t that popular any more BASIC reads almost like English, and all its commands and instructions are English words — or at least English words missing a few vowels or severely disobeying the laws of spelling. The lowest of the low-level programming languages is machine language. That language is the actual primitive grunts and groans of the microprocessor itself. Machine language consists of numbers and codes that the microprocessor understands and executes. Therefore, no one really writes programs in machine language; rather, they use assembly language, which is one step above the low-level machine language because the grunts and groans are spelled out rather than entered as raw numbers. Why would anyone use a low-level language when high-level languages exist? Speed! Programs written in low-level languages run as fast as the computer can run them, often many times faster than their high-level counterparts. Plus, the size of the program is smaller. A program written in Visual Basic may be 34K in size, but the same program written in assembly language may be 896 bytes long. On the other hand, the time it takes to develop an assembly language program is much longer than it would take to write the same program in a higher-level language. It’s a trade-off. The C programming language is considered a mid-level language. It has parts that are low-level grunting and squawking, and also many high-level parts that read like any sentence in a Michael Crichton novel, but with more character development. In C, you get the best of the high-level programming languages and the speed of development they offer and you also get the compact program size and speed of a low- level language. That’s why C is so bitchen. Note: No, I’m not being flip. C was developed at AT&T Bell Labs in the early 1970- 72s. At the time, Bell Labs had a programming language named B --B for Bell. The next language they created was C - one up on B. C is the offspring of both the B programming language and a language named BCPL, which stood for Basic Combined Programming Language. But you have to admit that the B story is cute enough by itself. You would think that the next, better version of C would be called the D language. But, no; it’s named C++. C is considered a mid-level language. See the nearby sidebar, “Stuff you don’t need to know about language levels,” for the boring details. The guy who created the C programming language at Bell Labs is Dennis Ritchie. I mention him in case you’re ever walking on the street and you happen to bump into Mr. Ritchie. In that case, you can say “Hey, aren’t you Dennis Ritchie, the guy who invented C?” And he’ll say “Why — why, yes I am.” And you can say “Cool.”