Table of Contents for
Intermediate C Programming

Version ebook / Retour

Cover image for bash Cookbook, 2nd Edition Intermediate C Programming by Yung-Hsiang Lu Published by CRC Press, 2015
  1. Front Cover
  2. Contents (1/2)
  3. Contents (2/2)
  4. List of Figures (1/2)
  5. List of Figures (2/2)
  6. List of Tables
  7. Foreword
  8. Preface
  9. Author, Reviewers, and Artist
  10. Rules in Software Development
  11. Source Code
  12. I. Computer Storage: Memory and File
  13. 1. Program Execution (1/2)
  14. 1. Program Execution (2/2)
  15. 2. Stack Memory (1/5)
  16. 2. Stack Memory (2/5)
  17. 2. Stack Memory (3/5)
  18. 2. Stack Memory (4/5)
  19. 2. Stack Memory (5/5)
  20. 3. Prevent, Detect, and Remove Bugs (1/2)
  21. 3. Prevent, Detect, and Remove Bugs (2/2)
  22. 4. Pointers (1/6)
  23. 4. Pointers (2/6)
  24. 4. Pointers (3/6)
  25. 4. Pointers (4/6)
  26. 4. Pointers (5/6)
  27. 4. Pointers (6/6)
  28. 5. Writing and Testing Programs (1/4)
  29. 5. Writing and Testing Programs (2/4)
  30. 5. Writing and Testing Programs (3/4)
  31. 5. Writing and Testing Programs (4/4)
  32. 6. Strings (1/3)
  33. 6. Strings (2/3)
  34. 6. Strings (3/3)
  35. 7. Programming Problems and Debugging (1/4)
  36. 7. Programming Problems and Debugging (2/4)
  37. 7. Programming Problems and Debugging (3/4)
  38. 7. Programming Problems and Debugging (4/4)
  39. 8. Heap Memory (1/3)
  40. 8. Heap Memory (2/3)
  41. 8. Heap Memory (3/3)
  42. 9. Programming Problems Using Heap Memory (1/4)
  43. 9. Programming Problems Using Heap Memory (2/4)
  44. 9. Programming Problems Using Heap Memory (3/4)
  45. 9. Programming Problems Using Heap Memory (4/4)
  46. 10. Reading and Writing Files (1/3)
  47. 10. Reading and Writing Files (2/3)
  48. 10. Reading and Writing Files (3/3)
  49. 11. Programming Problems Using File (1/2)
  50. 11. Programming Problems Using File (2/2)
  51. II. Recursion
  52. 12. Recursion (1/4)
  53. 12. Recursion (2/4)
  54. 12. Recursion (3/4)
  55. 12. Recursion (4/4)
  56. 13. Recursive C Functions (1/4)
  57. 13. Recursive C Functions (2/4)
  58. 13. Recursive C Functions (3/4)
  59. 13. Recursive C Functions (4/4)
  60. 14. Integer Partition (1/5)
  61. 14. Integer Partition (2/5)
  62. 14. Integer Partition (3/5)
  63. 14. Integer Partition (4/5)
  64. 14. Integer Partition (5/5)
  65. 15. Programming Problems Using Recursion (1/5)
  66. 15. Programming Problems Using Recursion (2/5)
  67. 15. Programming Problems Using Recursion (3/5)
  68. 15. Programming Problems Using Recursion (4/5)
  69. 15. Programming Problems Using Recursion (5/5)
  70. III. Structure
  71. 16. Programmer-Defined Data Types (1/6)
  72. 16. Programmer-Defined Data Types (2/6)
  73. 16. Programmer-Defined Data Types (3/6)
  74. 16. Programmer-Defined Data Types (4/6)
  75. 16. Programmer-Defined Data Types (5/6)
  76. 16. Programmer-Defined Data Types (6/6)
  77. 17. Programming Problems Using Structure (1/4)
  78. 17. Programming Problems Using Structure (2/4)
  79. 17. Programming Problems Using Structure (3/4)
  80. 17. Programming Problems Using Structure (4/4)
  81. 18. Linked Lists (1/3)
  82. 18. Linked Lists (2/3)
  83. 18. Linked Lists (3/3)
  84. 19. Programming Problems Using Linked List (1/2)
  85. 19. Programming Problems Using Linked List (2/2)
  86. 20. Binary Search Trees (1/4)
  87. 20. Binary Search Trees (2/4)
  88. 20. Binary Search Trees (3/4)
  89. 20. Binary Search Trees (4/4)
  90. 21. Parallel Programming Using Threads (1/5)
  91. 21. Parallel Programming Using Threads (2/5)
  92. 21. Parallel Programming Using Threads (3/5)
  93. 21. Parallel Programming Using Threads (4/5)
  94. 21. Parallel Programming Using Threads (5/5)
  95. IV. Applications
  96. 22. Finding the Exit of a Maze (1/5)
  97. 22. Finding the Exit of a Maze (2/5)
  98. 22. Finding the Exit of a Maze (3/5)
  99. 22. Finding the Exit of a Maze (4/5)
  100. 22. Finding the Exit of a Maze (5/5)
  101. 23. Image Processing (1/3)
  102. 23. Image Processing (2/3)
  103. 23. Image Processing (3/3)
  104. 24. Huffman Compression (1/10)
  105. 24. Huffman Compression (2/10)
  106. 24. Huffman Compression (3/10)
  107. 24. Huffman Compression (4/10)
  108. 24. Huffman Compression (5/10)
  109. 24. Huffman Compression (6/10)
  110. 24. Huffman Compression (7/10)
  111. 24. Huffman Compression (8/10)
  112. 24. Huffman Compression (9/10)
  113. 24. Huffman Compression (10/10)
  114. A. Linux
  115. B. Version Control
  116. C. Integrated Development Environments (IDE) (1/3)
  117. C. Integrated Development Environments (IDE) (2/3)
  118. C. Integrated Development Environments (IDE) (3/3)
Preface
Why Is This Book Needed?
There are hundreds of books about programming, many of them about C programming.
Why do I write this book? Why should you spend time reading it? How is this book different
from any other book? Like many authors, I wanted to write this book because I perceive a
need for it. Because I think the approach in this book is better.
I divide existing programming books into two types: introductory and advanced.In-
troductory books are written for beginners. These books assume readers have no back-
ground in programming and explain the basic concepts, sometimes starting with the “Hello
World!” program: a program that prints a Hello World!” message on the computer screen.
These books explain language features step-by-step: keywords, data types, control struc-
tures, strings, file operations, and so on. These books have a common characteristic: Every
program is short, usually one or two pages. This works because a short program can serve
to explain one new concept about the programming language. If we think of learning a
computer language as learning a natural language like English, Chinese, French, or Korean,
these books teach us how to write sentences and short paragraphs.
The second type of book is written for people comfortable with programming. These
books describe programs solving real problems. Many books about computer games or
graphics belong to this second category. The examples in these books are usually quite
long, sometimes thousands of lines of code, and too long to print inside the books. As a
result, only sections of the programs are explained in the books, and the source code is
either included on a CD or can be downloaded from the Internet. These books do not talk
about how to write programs. Instead, they focus mostly on algorithms to solve particular
problems and, sometimes, include detailed information on performance. You definitely won’t
find “Hello World!” examples anywhere in these books. Returning to the natural language
analogy, these books teach us how to write short novels, maybe a twenty-page story.
The problem is that it is difficult to jump from writing a paragraph to writing a novel.
A Book for Intermediate-Level Students
There are very few books for intermediate-level students. These students know something
about programming already. They are not surprised when they see if or while. They know
how to create functions and call functions. They can write short programs, perhaps dozens
of lines of code, but they are not ready to handle thousand-line programs. They make
mistakes often but most books talk about how to write correct programs without much
help with avoiding common mistakes. The students are unfamiliar with many concepts and
tools that can help them write better programs. These students need a stepping stone to
xxiii
xxiv Preface
take them from being capable of writing short programs to being capable of writing real
programs.
Currently, the gap is partially filled by books that cover Data Structures and Algo-
rithms. These books provide programs that implement the data structures or algorithms.
However, this is not an ideal solution. These books focus on the subjects, Data Structures
and Algorithms, but rarely provide information that helps students write correct code. In
fact, they usually include the programs without much explanation. They do not explain
programming concepts—for example, why a function needs a pointer as an argument or
the difference between deep and shallow copy. As a result, students have to learn these
programming skills by themselves.
To fill this need, I am writing this book for intermediate-level students. This book is
ideal as a second book on programming.
An Emphasis on Preventing Mistakes (“Bugs”) and Debugging
Most programming books talk about how to write programs. However, very few books
talk about how to develop software. Developing software is not simply typing code. Develop-
ing software requires much more knowledge and skill. To bridge this gap, it is useful to learn
by studying what is correct and what is wrong. Explaining how to write correct programs
is insufficient. It is also important to explain common mistakes and compare them with
correct programs.
A careless mistake can make a program behave unexpectedly. Worse, the program may
be correct in some scenarios and wrong in others. Such bugs are difficult to find as well as
to correct. This book explains some common mistakes so that readers understand how to
prevent making these mistakes. Debugging is ignored in most books. Few books mention
the word “debugger” and sometimes readers simply do not know the existence of such tools.
Learning how to use a debugger takes less than thirty minutes and can save many hours.
Even fewer books talk about how to use debuggers and the strategies for debugging.
Integration of Programming and Discrete Mathematics
Programming and discrete mathematics are two important subjects in computing. How-
ever, most books treat these two topics independently. It is rare to see mathematical equa-
tions in programming books. It is rare to see code in books on discrete mathematics. I
believe that students can benefit if they can see a closer connection between these two
subjects, as is shown in this book.
WhyDoesThisBookUseC?
C was invented in the late 1960s and early 1970s. Many languages were invented after
C and some of them were strongly influenced by C. Despite its age, the simplicity of C
Preface xxv
has ensured that it remains the foundation of computing on almost all modern platforms.
Like many operating systems, Linux is written in C. Android is mostly written in Java but
has an interface with C, called JNI (Java Native Interface). Most computer languages can
communicate with and through C. In fact, this is generally required for a programming
language to be useful, since most operating system interfaces use C. When a brand new
system is designed, C is often the first (in many cases, the only) programming language
supported by the system.
C is a good choice for intermediate-level students because learning C requires knowing
many concepts about computers. The web site langpop.com compares the popularity of
programming languages and C is the most popular language, followed by Java. A report
in IEEE Spectrum [1] ranks popular programming languages. This report considers four
types of software: mobile, enterprise, embedded, and web. C is the most popular language
for embedded systems. When all four types are considered, the top five are:
1. Java (100%)
2. C (99.3%)
3. C++ (95.5%)
4. Python (93.4%)
5. C# (92.4%)
As you can see, three (C, C++, C#) of the top five languages are based on C. Java is
influenced by C++.
Who should read this book?
If you are a student in computer science, computer engineering, or electrical engineer-
ing, you should definitely read this book. This book covers many concepts essential for
understanding how programs work inside computers. If your major is engineering, science,
mathematics, or technology, you will very likely need to work with computers and this book
will be helpful. If your major is not engineering, science, mathematics, or technology, you
may still find many concepts in this book (such as recursion) useful.
[1] Stephen Cass, Nick Diakopoulos, Joshua J. Romero, “Interactive: The Top Programming
Languages IEEE Spectrums 2014 Ranking”, July 1, 2014, http://spectrum.ieee.org/
static/interactive-the-top- programming-languages.
This page intentionally left blankThis page intentionally left blank