This textbook is an ideal introduction in college courses or self-study for learning computer programming using the C language. Written for those with minimal or no programming experience, Computer Programming in C for Beginners offers a heavily guided, hands-on approach that enables the reader to quickly start programming, and then progresses to cover the major concepts of C programming that are critical for an early stage programmer to know and understand. While the progression of topics is conventional, their treatment is innovative and designed for rapid understanding of the many concepts in C that have traditionally proven difficult for beginners, such as variable typing and scope, function definition, passing by value, pointers, passing by reference, arrays, structures, basic memory management, dynamic memory allocation, and linked lists, as well as an introductory treatment of searching and sorting algorithms.
Written in an informal but clear narrative, the book uses extensive examples throughout and provides detailed guidance on how to write the C code to achieve the objectives of the example problems. Derived from the author’s many years of teaching hands-on college courses, it encourages the reader to follow along by programming the progressively more complex exercise programs presented. In some sections, errors are purposely inserted into the code to teach the reader about the common pitfalls of programming in general, and the C language in particular.
Author(s): Avelino J. Gonzalez
Edition: 1
Publisher: Springer
Year: 2020
Language: English
Pages: 193
Tags: c17 c codeblocks gcc linux
Preface
Contents
1: Creating a Simple C Program, Compiling, and Executing It
1 Downloading and Installing Code::Blocks
2 Compiling and Executing Your First C Program
3 Anatomy of a C Program
3.1 The main() Function
3.2 Pre-processor Directives
3.3 Comments
4 Creating Your First Program
5 Summary
6 Problems
2: Variables, Memory, and Operators
1 Variables – A Brief Introduction
2 Some Operations on Simple Variables
2.1 Data Typing in Variables
2.2 Defining and Initializing Variables
2.3 Setting and Reading the Values of Variables
2.3.1 Integer Variables
2.3.2 Floating Point Variables
2.3.3 Double Precision Floating Point Variables
2.3.4 Character Variables
2.4 Mixing up Data Types
3 Working with Variables and Operators
3.1 Addition, Subtraction, and Multiplication
3.2 Division
3.2.1 Integer Division
3.2.2 Mixing up Integer and Floating Point Division
3.3 Increment/Decrement Operators
3.4 Boolean Operators
3.5 Embedded Operations in C
4 Input/Output Functions
5 Constants
6 Summary
7 Problems
3: Selection Structures
1 Selection Structures – A Short Introduction
2 Single-Selection Structures
2.1 Exactly What Is Defined as the “Designated Code”?
2.2 How Does One Handle the “Otherwise” Case?
3 Double-Selection Structures
4 Multiple-Selection Structures
5 The break; and the return; Statements
6 The switch Structure
7 Summary
8 Problems
4: Repetition Structures
1 Repetition Structures – A Short Introduction
2 for Loops
3 The while Loop
4 The do-while Loop
5 Generating Random Numbers in C
6 Alternative Ways to Work with the Repetition Constructs
7 Nested Loops
8 Summary
9 Problems
5: Defining and Calling Functions
1 Defining and Calling Functions – A Short Introduction
2 Defining Functions
3 Calling Functions
4 Returning Values
5 Passing Values of Variables to Functions
6 Scope of Variables
6.1 Global Variables
6.2 Local Variables
6.3 Static Variables
7 Summary and Conclusion
8 Problems
6: Pointer Variables
1 Pointers – A Short Introduction
2 Declaring and Initializing Pointers
3 Input/Output with Pointers
4 Calling Functions by Reference with Pointers
5 Pointer Math
6 Double Pointers
7 Summary and Conclusion
8 Problems
7: Arrays
1 Arrays – A Short Introduction
2 Defining and Initializing Arrays
3 Arrays, Pointers and Pointer Math
4 Arrays and Loops
5 Passing Arrays to Functions
6 Character Arrays – Strings
6.1 Inputting Strings with scanf()
6.2 Printing Strings with printf()
7 Multi-dimensional Arrays
8 Summary and Conclusion
9 Problems
8: Structures
1 Structures – A Brief Introduction
2 Instantiating Structure Variables
2.1 Instantiating within the Body of the struct Definition
2.2 Instantiating Structure Variables Using the Structure Tag
2.3 Defining New Structure Data Types with typedef
3 Member Access Operators: The Dot and the Arrow Operators
4 Passing Structures to Functions
5 Structures, Arrays, and Loops
6 Summary and Conclusion
7 Problems
9: Strings and Advanced I/O
1 Strings – A Deeper Treatment
1.1 Initializing Strings
1.2 Setting Values to String Variables
1.3 The Length of a String
1.4 Comparing Strings
1.5 Concatenating Strings
2 Other Input/Output Functions in C for Characters and Strings
2.1 The puts() Function
2.2 The putchar() Function
2.3 The gets() Function
2.4 The getchar() Function
3 Optional Formatting Features of printf()
3.1 The width Specifier
3.2 The .precision Specifier
3.3 The flag Specifier
3.4 Really Long Strings in printf()
4 Escape Characters
5 External File I/O
5.1 Writing to External Files
5.2 Reading from External Files
5.3 What About That Thing Where fopen() Returns NULL?
6 Summary and Conclusion
7 Problems
10: Multi-file Programs
1 Programming Considerations When Building Multi-file Programs
1.1 The Obvious Ones
1.2 Scope of Variables
1.3 Scope of User-Defined Functions
2 Our Example Program
3 Case 1: Simple Split with Local Variables
4 Case 2: More Complex Version Using Local Variables
5 Case 3: Introducing Global Variables into the Equation
6 Case 4: Complicating the Issue with More Global Variables
7 Case 5: More Complex Still – Functions That Are Not Seen
8 Case 6: The Use of static for Functions
9 Summary and Conclusion
10 Problems
11: Dynamically-Allocated Memory and Linked Lists
1 An Introduction to Defining Variables During Run Time
2 How to Allocate Memory Dynamically for Variables
3 Linked Structures – A Brief Introduction
4 How to Link Together Dynamically-Allocated Memory
5 Traversing a Linked List
6 Inserting Nodes into an Existing Linked List
6.1 Inserting New Nodes at the Front of the Linked List
6.2 Inserting New Nodes at the Tail of the Linked List
6.3 Inserting a New Node Somewhere in Between
7 Deleting Nodes from the List
8 Doubly-Linked Lists
9 Summary and Conclusion
10 Problems
12: Searching and Sorting
1 Searching – A Brief Introduction
2 The Sequential Search
2.1 Sequential Search of an Array for the First Appearance of a Key
2.2 Sequential Search of an Array for Multiple Appearances of a Key
2.3 Sequential Search of a Linked List
2.4 Thoughts on Advanced Search Techniques
3 Sorting a List
3.1 SelectionSort Algorithm
3.2 BubbleSort Algorithm
3.3 Thoughts on Advanced Sorting Algorithms
4 Summary and Conclusion
5 Problems
Glossary
Index