You are on page 1of 51

Beginning C: From Beginner to Pro, 7th

Edition German Gonzalez-Morris


Visit to download the full and correct content document:
https://ebookmass.com/product/beginning-c-from-beginner-to-pro-7th-edition-german-
gonzalez-morris/
German Gonzalez-Morris and Ivor Horton

Beginning C
From Beginner to Pro
7th ed.
German Gonzalez-Morris
Santiago, Chile

Ivor Horton
STRATFORD UPON AVON, UK

ISBN 979-8-8688-0148-8 e-ISBN 979-8-8688-0149-5


https://doi.org/10.1007/979-8-8688-0149-5

© German Gonzalez-Morris and Ivor Horton 2013, 2020, 2024

This work is subject to copyright. All rights are solely and exclusively
licensed by the Publisher, whether the whole or part of the material is
concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in
any other physical way, and transmission or information storage and
retrieval, electronic adaptation, computer software, or by similar or
dissimilar methodology now known or hereafter developed.

The use of general descriptive names, registered names, trademarks,


service marks, etc. in this publication does not imply, even in the
absence of a specific statement, that such names are exempt from the
relevant protective laws and regulations and therefore free for general
use.

The publisher, the authors, and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.
This Apress imprint is published by the registered company APress
Media, LLC, part of Springer Nature.
The registered company address is: 1 New York Plaza, New York, NY
10004, U.S.A.
To my family, Patricia, Raimundo, and Gregorio
—German Gonzalez-Morris
In memory of my beautiful wife, Eve
—Ivor Horton
Introduction
Welcome to Beginning C: From Beginner to Pro, Seventh Edition. With
this book, you can become a competent C programmer using the latest
version of the C language. In many ways, C is an ideal language with
which to learn programming. It’s very compact, so there isn’t a lot of
syntax to learn before you can write real applications. In spite of its
conciseness, it’s extremely powerful and is used by professionals in
many different areas. The power of C is such that it can be applied at all
levels, from developing device drivers and operating system
components to creating large-scale applications. A relatively new area
for C is in application development for mobile phones.
C compilers are available for virtually every kind of computer, so
when you’ve learned C, you’ll be equipped to program in just about any
context. Once you know C, you have an excellent base from which you
can build an understanding of the object-oriented C++.
My objective in this book is to minimize what I think are the three
main hurdles the aspiring programmer must face: coming to grips with
the jargon that pervades every programming language, understanding
how to use the language elements (as opposed to merely knowing what
they are), and appreciating how the language is applied in a practical
context.
Jargon is an invaluable and virtually indispensable means of
communication for the expert professional as well as the competent
amateur, so it can’t be avoided. My approach is to ensure that you
understand the jargon and get comfortable using it in context. In this
way, you’ll be able to more effectively use the documentation that
comes along with the typical programming product and also feel
comfortable reading and learning from the literature that surrounds
most programming languages.
Comprehending the syntax and effects of the language elements is
obviously an essential part of learning C, but appreciating how the
language features work and how they are used is equally important.
Rather than just using code fragments, I provide you with practical
working examples in each chapter that show how the language features
can be applied to specific problems. These examples provide a basis for
you to experiment and see the effects of changing the code.
Your understanding of programming in context needs to go beyond
the mechanics of applying individual language elements. To help you
gain this understanding, I conclude most chapters with a more complex
program that applies what you’ve learned in the chapter. These
programs will help you gain the competence and confidence to develop
your own applications and provide you with insight into how you can
apply language elements in combination and on a larger scale. Most
importantly, they’ll give you an idea of what’s involved in designing real
programs and managing real code.
The book’s spirit is to start from a beginner and finish as a pro.
Nevertheless, as usual, technology is broad and complex for each part
of the knowledge. Therefore, there is always a space to learn more
profoundly about each topic. I encourage you to keep learning and
researching each aspect you find more interesting (new knowledge is
always good).
It’s important to realize a few things that are true for learning any
programming language. First, there is quite a lot to learn, but this
means you’ll gain a greater sense of satisfaction when you’ve mastered
it. Second, it’s great fun, so you really will enjoy it. Third, you can only
learn programming by doing it, and this book helps you along the way.
Finally, it’s certain you will make a lot of mistakes and get frustrated
from time to time during the learning process. When you think you are
completely stuck, you just need to be persistent. You will eventually
experience that eureka moment and realize it wasn’t as difficult as you
thought.

How to Use This Book


Because I believe in the hands-on approach, you’ll write your first
programs almost immediately. Every chapter has several complete
programs that put theory into practice, and these are key to the book.
You should type in and run all the examples that appear in the text
because the very act of typing them in is a tremendous memory aid. You
should also attempt all the exercises that appear at the end of each
chapter. When you get a program to work for the first time—
particularly when you’re trying to solve your own problems—you’ll
find that the great sense of accomplishment and progress makes it all
worthwhile.
The pace is gentle at the start, but you’ll gain momentum as you get
further into the subject. Each chapter covers quite a lot of ground, so
take your time and make sure you understand everything before
moving on. Experimenting with the code and trying out your own ideas
are important parts of the learning process. Try modifying the
programs and see what else you can make them do—that’s when it gets
really interesting. And don’t be afraid to try things out—if you don’t
understand how something works, just type in a few variations and see
what happens. It doesn’t matter if it’s wrong. You’ll find you often learn
a lot from getting it wrong. A good approach is to read each chapter
through, get an idea of its scope, and then go back and work through all
the examples.
You might find some of the end-of-chapter programs quite difficult.
Don’t worry if it’s not all completely clear on the first try. There are
bound to be bits that you find hard to understand at first because they
often apply what you’ve learned to rather complicated problems. If you
really get stuck, you can skip the end-of-chapter exercises, move on to
the next chapter, and come back to them later. You can even go through
the entire book without worrying about them. However, if you can
complete the exercises, it shows you are making real progress.
Who This Book Is For
Beginning C, Seventh Edition is designed to teach you how to write
useful programs in C as quickly and easily as possible. By the end of
Beginning C, you’ll have a thorough grounding in programming the C
language. This is a tutorial for those of you who’ve done a little bit of
programming before, understand the concepts behind it, and want to
further your knowledge by learning C. However, no previous
programming knowledge on your part is assumed, so if you’re a
newcomer to programming, the book will still work for you.

What You Need to Use This Book


To use this book, you’ll need a computer with a C compiler and library
installed, so you can execute the examples, and a program text editor
for preparing your source code files. The compiler you use should
provide good support for the current international standard for the C
language, C23 (ISO/IEC 9899:2023), which is a significant update to
replace the C17 standard, commonly referred to as C23 or C2x. You’ll
also need an editor for creating and modifying your code. You can use
any plain text editor such as Notepad++ or vi to create your source
program files. However, you’ll get along better if your editor is designed
for editing C code.
I can suggest two sources for a suitable C compiler, both of which
are freeware:
The GNU C compiler, GCC, is available from gcc.gnu.org and
supports a variety of operating system environments (version 13+).
The Pelles C compiler for Microsoft Windows is downloadable from
www.smorgasbordet.com/pellesc/ and includes an excellent
integrated development environment (IDE) (version 12+).

Conventions Used
I use a number of different styles of text and layout in the book to help
differentiate between the different kinds of information. For the most
part, their meanings will be obvious. Program code will appear like
this:
int main(void)
{
printf("Beginning C\n");
return 0;
}
When a code fragment is a modified version of a previous instance, I
occasionally show the lines that have changed in bold type like this:

int main(void)
{
printf("Beginning C by Ivor Horton & German
Gonzalez-Morris\n");
return 0;
}

When code appears in the text, it has a different typestyle that looks
like this: double.
I’ll use different types of “brackets” in the program code. They aren’t
interchangeable, and their differences are very important. I’ll refer to
the symbols ( ) as parentheses, the symbols { } as braces, and the
symbols [ ] as square brackets.
Important new words in the text are shown in italic like this.
Any source code or other supplementary material referenced by the
author in this book is available to readers on GitHub via the book’s
product page, located at www.apress.com/9781484259757. For
more detailed information, please visit www.apress.com/source-
code.
Any source code or other supplementary material referenced by the
author in this book is available to readers on GitHub. For more detailed
information, please visit
https://www.apress.com/gp/services/source-code.
Acknowledgments
I am profoundly grateful to Patricia Cruces, my life partner, whose
infinite patience, unwavering support, and boundless love have been
my constant companions through every challenge and triumph. Her
presence has been a source of inspiration, making this journey more
meaningful and fulfilling.
To my sons, Raimundo and Gregorio, I owe immeasurable thanks for
being the bright sparks of joy and inspiration in my life. Your happiness
reminds me of what truly matters, and your enthusiasm fills me with
determination.
To my parents, Germá n and Felicia Morris, who have been my pillars
of strength, providing both love and guidance and invaluable
educational opportunities.
To my friend Daniel Lagos, a great engineer, whose constructive
criticism, suggestions, exchange of ideas, and feedback have not only
helped my understanding with his input but have inspired me to
explore alternative approaches and support continuous improvement.
I appreciate the collaborative spirit demonstrated by my university
classmates Alejandro Cuevas and Fernando Castillo, as their diverse
perspectives have contributed to more comprehensive, real-world
examples and practical applications, particularly to my lessons on C
language pointers.
I am grateful for the support and opportunities provided to me by
the entire Apress team, especially Melissa Duffy and Sowmya Thodur.
Their guidance and advice have been invaluable. I also want to thank
Megan Hirni, the technical reviewer, for her clever feedback,
suggestions, and corrections.
—German Gonzalez-Morris
Table of Contents
Chapter 1:​Programming in C
The C Language
The Standard Library
Learning C
Creating C Programs
Editing
Compiling
Linking
Executing
Creating Your First Program
Editing Your First Program
Dealing with Errors
Dissecting a Simple Program
Comments
Preprocessing Directives
Defining the main() Function
Keywords
The Body of a Function
Outputting Information
Function Arguments
Control Characters
Trigraph Sequences
The Preprocessor
Developing Programs in C
Understanding the Problem
Detailed Design
Implementation
Testing
Functions and Modular Programming
Common Mistakes
Points to Remember
Summary
Chapter 2:​First Steps in Programming
Memory in Your Computer
What Is a Variable?​
Naming Variables
Variables That Store Integers
Using Variables
Initializing Variables
More on Division with Integers
Unary Operators
Unary Minus Operator
Variables and Memory
Signed Integer Types
Unsigned Integer Types
Specifying Integer Constants
Binary Integer Constants
Working with Floating-Point Numbers
Floating-Point Number Representation
Floating-Point Variables
Division Using Floating-Point Values
Controlling the Number of Decimal Places in the Output
Controlling the Output Field Width
More Complicated Expressions
Checked Integer Arithmetic
constexpr
Defining Named Constants
Knowing Your Limitations
Introducing the sizeof Operator
Choosing the Correct Type for the Job
Explicit Type Conversion
Automatic Conversions
Rules for Implicit Conversions
Implicit Conversions in Assignment Statements
Type Inference
typeof
More Numeric Data Types
Character Type
Character Input and Character Output
Enumerations
Choosing Enumerator Values
Unnamed Enumeration Types
Variables That Store Boolean Values
The op=​Form of Assignment
Mathematical Functions
Designing a Program
The Problem
The Analysis
The Solution
Summary
Chapter 3:​Making Decisions
The Decision-Making Process
Arithmetic Comparisons
The Basic if Statement
Extending the if Statement:​if-else
Using Blocks of Code in if Statements
Nested if Statements
Testing Characters
Logical Operators
The Conditional Operator
Operator Precedence:​Who Goes First?​
Multiple-Choice Questions
Using else-if Statements for Multiple Choices
The switch Statement
The goto Statement
Bitwise Operators
The op=​Use of Bitwise Operators
Using Bitwise Operators
Bit-Precise Integers
Modern Bit Utilities
Designing a Program
The Problem
The Analysis
The Solution
Summary
Chapter 4:​Loops
How Loops Work
Introducing the Increment and Decrement Operators
The for Loop
General Form of the for Loop
More on the Increment and Decrement Operators
The Increment Operator
The Prefix and Postfix Forms of the Increment Operator
The Decrement Operator
The for Loop Revisited
Modifying the for Loop Control Variable
A for Loop with No Parameters
The break Statement in a Loop
Limiting Input Using a for Loop
Generating Pseudo-random Integers
More for Loop Control Options
Floating-Point Loop Control Variables
Chars loop Control Variables
The while Loop
Nested Loops
Nested Loops and the goto Statement
The do-while Loop
The continue Statement
Designing a Program
The Problem
The Analysis
The Solution
Summary
Chapter 5:​Arrays
An Introduction to Arrays
Programming Without Arrays
What Is an Array?​
Using an Array
The Address of Operator
Arrays and Addresses
Initializing an Array
Compound Literal
Finding the Size of an Array
Multidimensional​Arrays
Initializing Multidimensional​Arrays
Constant Arrays
Variable-Length Arrays
Designing a Program
The Problem
The Analysis
The Solution
Summary
Chapter 6:​Applications with Strings and Text
What Is a String?​
Variables That Store Strings
Arrays of Strings
Operations with Strings
Checking for C11/​C23 Support
Finding the Length of a String
Copying Strings
Concatenating Strings
Comparing Strings
Searching a String
Tokenizing a String
Reading Newline Characters into a String
Analyzing and Transforming Strings
Converting Character Case
Converting Strings to Numerical Values
Designing a Program
The Problem
The Analysis
The Solution
Summary
Chapter 7:​Pointers
A First Look at Pointers
Declaring Pointers
Accessing a Value Through a Pointer
Using Pointers
Testing for a NULL Pointer
Pointers to Constants
Constant Pointers
Naming Pointers
Arrays and Pointers
Multidimensional​Arrays
Multidimensional​Arrays and Pointers
Accessing Array Elements
Using Memory As You Go
Dynamic Memory Allocation:​The malloc() Function
Releasing Dynamically Allocated Memory
Memory Allocation with the calloc() Function
Extending Dynamically Allocated Memory
Handling Strings Using Pointers
Using Arrays of Pointers
Pointers and Array Notation
Designing a Program
The Problem
The Analysis
The Solution
The Complete Program
Summary
Chapter 8:​Structuring Your Programs
Program Structure
Variable Scope and Lifetime
Variable Scope and Functions
Storage classes
Functions
Defining a Function
The return Statement
The Pass-by-Value Mechanism
Function Prototypes
Pointers As Parameters and Return Types
const Parameters
Perils of Returning Pointers
Summary
Chapter 9:​More on Functions
Pointers to Functions
Declaring a Pointer to a Function
Calling a Function Through a Function Pointer
Arrays of Pointers to Functions
Pointers to Functions As Arguments
Variables in Functions
Static Variables:​Keeping Track Within a Function
Sharing Variables Between Functions
Functions That Call Themselves:​Recursion
Functions with a Variable Number of Arguments
Copying a va_​list
Basic Rules for Variable-Length Argument Lists
The main( ) Function
Terminating a Program
The abort() Function
The exit() and atexit() Functions
The _​Exit() Function
The quick_​exit() and at_​quick_​exit() Functions
Enhancing Performance
Declaring Functions Inline
Using the restrict Keyword
The _​Noreturn Function Specifier
Attributes
Designing a Program
The Problem
The Analysis
The Solution
Summary
Chapter 10:​Essential Input and Output
Input and Output Streams
Standard Streams
Input from the Keyboard
Formatted Keyboard Input
Input Format Control Strings
Characters in the Input Format String
Variations on Floating-Point Input
Reading Hexadecimal and Octal Values
Reading Characters Using scanf_​s()
String Input from the Keyboard
Single-Character Keyboard Input
Output to the Screen
Formatted Output Using printf_​s()
Escape Sequences
Integer Output
Outputting Floating-Point Values
Character Output
Other Output Functions
Unformatted Output to the Screen
Formatted Output to an Array
Formatted Input from an Array
Summary
Chapter 11:​Structuring Data
Data Structures:​Using struct
Defining Structure Types and Structure Variables
Accessing Structure Members
Unnamed Structures
Arrays of Structures
Structure Members in Expressions
Pointers to Structures
Dynamic Memory Allocation for Structures
More on Structure Members
Structures As Members of a Structure
Declaring a Structure Within a Structure
Pointers to Structures As Structure Members
Doubly Linked Lists
Bit Fields in a Structure
Structures and Functions
Structures As Arguments to Functions
Pointers to Structures As Function Arguments
Structure As a Function Return Value
Binary Trees
Sharing Memory
Designing a Program
The Problem
The Analysis
The Solution
Summary
Chapter 12:​Working with Files
The Concept of a File
Positions in a File
File Streams
Accessing Files
Opening a File
Buffering File Operations
Renaming a File
Closing a File
Deleting a File
Writing a Text File
Reading a Text File
Reading and Writing Strings to a Text File
Formatted File Input and Output
Formatted Output to a File
Formatted Input from a File
Dealing with Errors
More Open Modes for Text Files
The freopen_​s( ) Function
Binary File Input and Output
Opening a File in Binary Mode
Writing a Binary File
Reading a Binary File
Moving Around in a File
File Positioning Operations
Finding Out Where You Are
Setting a Position in a File
Using Temporary Work Files
Creating a Temporary Work File
Creating a Unique File Name
Updating Binary Files
Changing the Contents of a File
Creating a Record from Keyboard Input
Writing a Record to a File
Reading a Record from a File
Writing a File
Listing the File Contents
Updating the Existing File Contents
File Open Mode Summary
Designing a Program
The Problem
The Analysis
The Solution
Summary
Chapter 13:​The Preprocessor and Debugging
Preprocessing
Including Header Files
Defining Your Own Header Files
Managing Multiple Source Files
External Variables
Static Functions
Substitutions in Your Program Source Code
Macros
Macros That Look Like Functions
Strings As Macro Arguments
Joining Two Arguments in a Macro Expansion
Preprocessor Directives on Multiple Lines
Logical Preprocessor Directives
Conditional Compilation
Testing for Multiple Conditions
Undefining Identifiers
Testing for Specific Values for Identifiers
Multiple-Choice Selections
Standard Preprocessing Macros
_​Generic Macro
The Unreachable Macro
Debugging Methods
Integrated Debuggers
The Preprocessor in Debugging
Assertions
Date and Time Functions
Getting Time Values
Getting the Date
Getting the Day for a Date
Summary
Chapter 14:​Advanced and Specialized Topics
Working with International Character Sets
Understanding Unicode
Setting the Locale
The Wide Character Type wchar_​t
Operations on Wide Character Strings
File Stream Operations with Wide Characters
Fixed Size Types That Store Unicode Characters
Specialized Integer Types for Portability
Fixed-Width Integer Types
Minimum-Width Integer Types
Maximum-Width Integer Types
The Complex Number Types
Complex Number Basics
Complex Types and Operations
Programming with Threads
Creating a Thread
Exiting a Thread
Joining One Thread to Another
Suspending a Thread
Managing Thread Access to Data
Summary
Appendix A:​Computer Arithmetic
Appendix B:​ASCII Character Code Definitions
Appendix C:​Reserved Words in C
Appendix D:​Input and Output Format Specifications
Appendix E:​Standard Library Header Files
Index
About the Authors
German Gonzalez-Morris
is a polyglot software architect/engineer
with 20+ years in the field, with
knowledge in Java, SpringBoot, C/C++,
Julia, Python, Haskell, and JavaScript,
among others. He works for cloud
(architecture), web-distributed
applications, and microservices. German
loves math puzzles (including reading
Knuth, proud of solving some of Don’s
puzzles), swimming, and table tennis.
Also, he has reviewed several books,
including those on application
containers (WebLogic) and languages (C,
Java, Spring, Python, Haskell, TypeScript,
WebAssembly, Math for coders, regexp,
Julia, data structures, and algorithms).
You can see details on his blog
(https://devwebcl.blogspot.com/) or X/Twitter account
(@devwebcl)

Ivor Horton
is self-employed in consultancy and writes programming tutorials. He
worked for IBM for many years and holds a bachelor’s degree, with
honors, in mathematics. Ivor’s experience at IBM includes
programming in most languages (such as assembler and high-level
languages on a variety of machines), real-time programming, and
designing and implementing real-time closed-loop industrial control
systems. He has extensive experience teaching programming to
engineers and scientists (Fortran, PL/1, APL, etc.). Ivor is an expert in
mechanical, process, and electronic CAD systems; mechanical CAM
systems; and DNC/CNC systems.
Another random document with
no related content on Scribd:
"It is probably unknown to the inhabitants of the Transvaal
and Orange River Colony that nearly 15,000 of their
fellow-subjects are now prisoners of war, not one of whom will
be released until those now in arms against us surrender
unconditionally. The burghers must by this time be cognisant
of the fact that no intervention on their behalf can come from
any of the Great Powers, and, further, that the British Empire
is determined to complete the work which has already cost her
so many valuable lives, and to carry to its conclusion the war
declared against her by the late Governments of the South
African Republic and Orange Free State, a war to which there
can be but one ending. If any further doubts remain in the
minds of the burghers as to Her Britannic Majesty's
intentions, they should be dispelled by the permanent manner
in which the country is gradually being occupied by Her
Majesty's Forces, and by the issue of the Proclamations signed
by me on the 24th May and 1st September 1900, annexing the
Orange Free State and the South African Republic respectively,
in the name of Her Majesty.

"I take this opportunity of pointing out that, except in the


small area occupied by the Boer army under the personal
command of Commandant-General Botha, the war is degenerating,
and has degenerated, into operations carried on in an
irregular and irresponsible manner by small, and in very many
cases, insignificant bodies of men. I should be failing in my
duty to Her Majesty's Government and to Her Majesty's Army in
South Africa if I neglected to use every means in my power to
bring such irregular warfare to an early conclusion. The means
which I am compelled to adopt are those which the customs of
war prescribe as being applicable to such cases. They are
ruinous to the country, and entail endless suffering on the
burghers and their families, and the longer this guerrilla
warfare continues the more vigorously must they be enforced."

Great Britain, Papers by Command:


1900, Cd. 420, page 78, and Cd. 426, page 17.
SOUTH AFRICA: The Transvaal: A. D. 1900 (October).
Proclamation of annexation to the British Dominions.

In terms similar to those used in proclaiming the annexation


of the Orange Free State (see above: MAY) the annexation of
the Transvaal to the Dominions of Her British Majesty was
proclaimed with great ceremony at Pretoria on the 25th of
October.

SOUTH AFRICA: The Field of War: A. D. 1900 (November).


Return of Lord Roberts to England, leaving Lord Kitchener
in command.

Having been appointed Commander-in-Chief of the British Army,


in the place of Lord Wolseley, Field-Marshal Lord Roberts, on
the 29th of November, delivered the command in South Africa to
Lord Kitchener, and returned to England. At the same time,
Lord Kitchener was raised to the rank of Lieutenant-General.

SOUTH AFRICA: Cape Colony and the Transvaal:


A. D. 1900 (December).
Afrikander Congress.
Lord Kitchener to the burghers of Pretoria.

From 6,000 to 8,000 persons were reported to be in attendance


at an "Afrikander Congress," held at Worcester, in Cape
Colony, December 6, which adopted the following resolutions:

"1. We men and women of South Africa assembled and represented


here, having heard the report of the people's deputation to
England, and having taken into earnest consideration the
deplorable condition into which the people of South Africa
have been plunged, and the grave danger threatening our
civilization, record our solemn conviction that the highest
interests of South Africa demand, first, the termination of
the war now raging with untold misery and horror, such as the
burning of houses, the devastation of the country, the
extermination of the white nationality, and the treatment to
which women and children are subjected, which will leave a
lasting heritage of bitterness and hatred, while seriously
endangering further relations between civilization and
barbarism in South Africa; secondly, the retention by the
Republics of their independence, whereby alone the peace of
South Africa can be maintained.

2. The congress desires full recognition of the right of the


people of this colony under its Constitution to settle and
manage their own affairs and to express grave disapproval of
the policy pursued and the attitude adopted in this matter by
the Governor and High Commissioner, his Excellency Sir Alfred
Milner.

3. The congress solemnly pledges itself to labour in a


constitutional way unceasingly for the above resolutions, and
resolves to send a deputation to his Excellency Sir Alfred
Milner, asking him to bring the resolutions officially to the
notice of her Majesty's Government."

On the 21st of December Lord Kitchener addressed a meeting, at


Pretoria, of burghers who had surrendered to the British and
who desired to bring about peace. In his remarks he was
reported to have said: "The Boers had fought a good fight, but
they were overpowered. There would be no dishonour in the
leaders recognizing this fact. The proclamations that had been
issued were of little use, as means were adopted to prevent
them from reaching the burghers. He trusted that the committee
would endeavour to acquaint the Boers in the field with the
true position. He desired to give them every chance to
surrender voluntarily, and to finish the war by the most
humane means possible. If the conciliatory methods now being
adopted failed he had other means which he would be obliged to
exercise. He would give the committee notice if the time
arrived to consider conciliation as a failure. The principal
difficulties were that burghers desirous of surrendering were
afraid they would not be allowed to remain in their own
districts or that they would be punished for violating their
oath of neutrality. General Kitchener declared that he had
issued instructions that burghers who surrendered would, with
their families and stock, be protected in their own districts.
Those who had broken the oath of neutrality under compulsion
would be accorded the same treatment. Deserted women and
children would be kept in laagers, where their friends could
freely join them. It was essential to clear the country. While
food remained the commandos were enabled to continue in the
field. General Kitchener added that it must be understood that
the British would not be responsible for stock unless it was
brought in and kept within protected limits. In conclusion
General Kitchener said that he had come to speak to the
burghers personally in order that they might be able to tell
their friends what they had heard from his own lips."

{508}

SOUTH AFRICA: The Field of War: A. D. 1900 (December).


Numbers of British troops employed in the war from the
beginning, and their losses.

See (in this volume)


ENGLAND: A. D. 1900 (DECEMBER).

SOUTH AFRICA: British Colonies: A. D. 1901 (January).


New heads of the Colonial Governments.

The following appointments were announced by the British


Colonial Office on the 4th of January, 1901: Sir Alfred Milner
to be Governor of the Transvaal and British High Commissioner.
The Honourable Sir Walter Francis Hely-Hutchinson (Governor of
Natal and Zululand since 1893) to be Governor of Cape Colony.
Lieutenant-Colonel Sir Henry C. McCallum (Governor of
Newfoundland since 1898, and aide-de-camp to the Queen since
1900) to be Governor of Natal. Major Hamilton John Goold-Adams
(Resident Commissioner of the Bechuanaland Protectorate) to be
Lieutenant-Governor of the Orange River Colony.

SOUTH AFRICA: Cape Colony: A. D. 1901 (January).


Boer invasion.
Declaration of martial law.

On New Year's Day, 1901, the Cape Town correspondent of the


"London Times" was compelled to write: "The immediate aspect
of affairs in Cape Colony at the opening of the new year is
scarcely less gloomy than at the beginning of 1900. The number
of Boers invading the country to-day may be less than it was a
year ago, but they have penetrated further south, and their
presence near such centres of hostile Dutch feeling as Graaf
Reinet constitutes an element of danger which was not present
last January. The proclamation issued this morning by the High
Commissioner calling for volunteers to defend the lines of
communication proves that the military authorities are at last
alive to the critical nature of the situation, but the measure
comes very late in the day."

On the 17th of January a cable message from Cape Town


announced: "An extraordinary gazette issued this afternoon
contains a proclamation placing the whole of the Cape Colony
under martial law, with the exception of the Cape Town,
Wynberg, Simonstown, Port Elizabeth and East London districts
and the territories of the Transkei, Tembuland, Griqualand and
East Pondoland. The gazette also states that the
peace-preservation act will be enforced in the Cape Colony,
Wynberg and Simonstown districts. Under this act all the civil
population will be called upon to deliver up their arms."

SOUTH AFRICA: Orange Free State: A. D. 1901 (January).


Peace movement.
Condition of country described.
Defiant proclamation of Steyn and De Wet.
Early in January, a "Central Peace Committee," formed at
Kroonstad, addressed an open letter to their fellow citizens,
appealing for submission and peace, saying: "The country is
literally one vast wilderness. The farmers are obliged to go
to the towns for protection, and huge refugee camps have been
formed by the British for them and their families. These
people have lost everything, and ruin and starvation stare
them in the face. All this misery is caused by a small and
obstinate minority, who will not bow to the inevitable and who
make the majority suffer. Any encouragement to the men still
on commando to continue the hopeless struggle can only injure
us and cause us further misery. We have done our best and
fought to get Africa under one flag, and we have lost. Let
there be no mistake about this. England has spent millions and
sacrificed thousands of lives, and no reasonable being can
believe for one moment that she will now give up the fruits of
victory. It is, therefore, a duty for us, her beaten foe, to
accept the terms offered by our conqueror. … We appeal to you
and ask you to appoint another congress, and nominate men of
influence out of your midst to visit Mr. Steyn and General De
Wet, and try to persuade them to accept the terms offered by
England. These two men are the only obstacles to peace. We ask
you to believe us when we say that Mr. Kruger and the late
Transvaal Government have been willing twice already to accept
British terms, but Mr. Steyn refused to have anything to do
with surrender. He continued the war and encouraged the
burghers in the hope that we should get European assistance.
To-day he is cut off from all communication with the outside
world. You know and we know how unfounded that hope is and it
is your duty to assist us to make him understand this. We
appeal to you to help us to make an end to this unhappy state
of affairs, which is plunging everybody into poverty and
despair."

As if in response to this cry for peace, Steyn and De Wet


issued the following proclamation a few days later: "Be it
known to all that the war which was forced on the Republics by
the British Government still rages in the Orange Free State
and in the South African Republic; and that the customs of
civilized warfare and also the Conventions of Geneva and The
Hague have not been observed by the enemy, who has not
scrupled, contrary to the Geneva Convention, to capture
doctors and ambulances and to deport them, in order to prevent
our wounded from getting medical assistance. He has seized
ambulances and material appertaining thereto, and has not
hesitated, contrary to the recognized primitive rules of
warfare, and contrary to his solemn agreement at The Hague, to
arrest neutrals and deport them, and to send out marauding
bands to plunder, burn, and damage the burghers' private
property. He has armed Kaffirs and natives and made use of
them against us in war. He has been continually busy capturing
women and children, old and sickly men. Many women's deaths
have been occasioned because the so-called Christian enemy had
no consideration for women on a sick bed or for those whose
state of health should have protected them against rough
treatment. Honourable women and tender children have not only
been treated roughly, but also in an insulting manner by the
soldiers, by order of their officers. Moreover, old mothers
and women have been raped, even wives and children. The
property of prisoners of war, and even of killed burghers, has
not been respected. In many instances the mother and father
have been taken from the house, which was thus left
unprotected, and all have been left to their fate, an easy
prey to the savage. The world has been untruthfully informed
by the enemy that he was obliged to carry out this destruction
because the burghers blew up the line and cut the wires, or
misused the white flag. Nearly all the houses in the two
Republics have been destroyed, whether in the neighbourhood of
the railway line or not; while with regard to the misuse of
the white flag, that is simply a continuance of the
everlasting calumny against which the Afrikander has had to
strive since God brought him into contact with Englishmen.
Robbing his opponent of his goods has not satisfied him; he
will not be satisfied till he has robbed him of his good name
also.

{509}

"Then he wishes to inform the world that the Republics are


conquered and the war ended, and that only here and there
small plundering bands are to be found who continue the strife
in an irresponsible manner. It is an untruth. The Republics
are not yet conquered. The war is not finished. The burgher
forces of the two Republics are still led by responsible
leaders, as from the commencement of the war, under the
supervision of the Governments of both Republics. The fact
that Lord Roberts and Lord Kitchener choose to term the
burgher forces marauding bands does not make them such.
Similarly, saying that the war is over does not put an end to
it while fighting still continues. When was this war over?
After the battle of Spion Kop or after Paardeberg? After the
occupation of Bloemfontein or Pretoria? Or perhaps after the
battles of Dewetsdorp or Commando Nek, in both of which
irregulars were captured and the enemy totally vanquished. The
burghers would be less than men if they allowed the enemy to
go unpunished after ill-treating their wives and destroying
their homes from sheer lust of destruction. Therefore a
portion of our burghers have again been sent into Cape Colony,
not only to wage war, but to be in a position to make
reprisals as they have already done in the case of the
ambulances. Therefore we again warn the officers of her
Majesty's troops that unless they cease the destruction of
property in the Republics, we shall wreak vengeance by
destroying the property of her Majesty's subjects who are
unkindly disposed to us; but at the same time, to avoid being
misunderstood, we hereby openly declare that the women and
children will always remain unmolested, despite anything done
to ours by her Majesty's troops. We ask for nothing from our
brothers in Cape Colony, but we call upon them, as well as
upon the civilized world, to assist on behalf of civilization
and Christianity in putting an end to the barbarous manner of
the enemy's warfare. Our prayer will always be that the God of
our fathers will not desert us in this unrighteous strife.

"On the field, January 14. STEYN. DE WET."

SOUTH AFRICA: The Field of War: A. D. 1901 (February).


Report of British military forces in South Africa from the
beginning of the war, with the number of killed and wounded
and the deaths from wounds and disease.

A Parliamentary paper issued on the 26th of February, 1901,


contained the following table, showing the strength of the
garrison in South Africa on the 1st of August, 1899, before
the beginning of the war, with the subsequent reinforcements
and casualties, and the total strength of forces on the 1st of
February, 1901:

|NON-COMMISSIONED
OFFICERS AND MEN.

OFFICERS|CAVALRY|ARTILLERY|INFANTRY|OTHERS|TOTAL|
TOTAL
AND
OFFICERS

MOUNTED AND MEN

INFANTRY
-------------------------------------------------
----------------------------
I. Garrison on
Aug. 1, 1899 318 1,127 1,035
6,428 1,032 9,622 9,940
-------------------------------------------------
----------------------------
II.
Reinforcements,
Aug. 1, 1899,
to Oct. 11, 1899
(outbreak of war)

(1.) From Home. 280 … 743


5,620 … 6,363 6,643
(2.) From India
(some of these did
not reach South
Africa until after
the outbreak of
hostilities) 259 1,564 653
3,427 … 5,644 5,903

-------------------------------------------------
-----------------------------
539 1,564 1,396
9,047 … 12,007 12,546
-------------------------------------------------
-----------------------------

III. Further
reinforcements
from Oct. 11,
1899, to end
of July, 1900

Regulars
(1.) From Home
and Colonies. 5,748 11,003 14,145
110,292 14,347 149,787 155,535
(2.) From India. 132 713 376
670 … 1,759 1,891

-------------------------------------------------
-----------------------------
5,880 11,716 14,521
110,962 14,347 151,546 157,426
-------------------------------------------------
-----------------------------

Colonials
(1.) From Colonies
other than
South African. 550 287 692
9,788 267 11,034 11,584
(2.) Raised in
South Africa. 1,387 … …
… … 28,932 30,319

-------------------------------------------------
------------------------------
1,937 … …
… … 39,966 41,903
-------------------------------------------------
------------------------------

Imperial yeomanry. 536 … …


… … 10,195 10,731
Volunteers from
United Kingdom. 342 … 358
9,995 434 10,787 11,129
Militia. 831 … 617
19,753 256 20,626 21,457

-------------------------------------------------
-------------------------------

Total all arms


sent to, and
raised in,
South Africa
up to Aug. 1, 1900,
including garrison
on Aug. 1, 1899. 10,383 … …
… … 254,749 265,132

-------------------------------------------------
-------------------------------

IV. Further
reinforcements
from Aug. 1, 1900,
to Jan. 31, 1901
(1.) Regulars 820 3,213 652
10,439 975 15,279 16,099
(2.) Militia 7 … …
1,141 … 1,141 1,148

-------------------------------------------------
-------------------------------

11,210 … …
… … 271,169 282,379
-------------------------------------------------
-------------------------------
{510}

NON-COMMISSIONED OFFICERS AND MEN.

Officers Cavalry.
Artillery. Infantry Others. Total. Total

and Officers

Mounted and Men

Infantry

V. Numbers
(1.) Killed to
Jan. 31, 1901 334.
3,346 3,680
(2.) Wounded to
Jan 31, 1901. 1,242.
14,914 16,156
(3.) Died of disease
or wounds or accidentally
killed in South Africa
to Jan. 31, 1001. 301.
9,008 9,309
(4.) Disbanded and
discharged in South Africa. 299.
5,231 5,530
(5.) In hospital in South
Africa on Dec. 28, 1900
(latest returns). 415.
13,716 14,131
VI. Numbers left
South Africa
(1.) For England
not invalids. 1,214
11,109 12,323
(2.) For England
sick, wounded, and
died on passage 1,703
39,095 40,198
(3.) Returned to India
direct from South Africa. 20
70 90
(4.) Returned to Colonies
direct from South Africa
(a) Regulars, including two
battalions to Ceylon. 98
2,041 2,139
(b) Colonials. 177
3,384 3,561

VII. Present strength of


Forces in South Africa,
Feb. 1, 1901
(1.) Regulars. 4,305 12,600
12,000 99,700 12,885 137,185 141,490
(2.) Colonials. 1,339
27,000 28,339*
(3.) Imperial yeomanry 495
7,500 7,995
4.) Volunteers. 200
7,500 7,700
5.) Militia. 725
18,700 19,425

TOTAL 7,064
197,885 204,949*

* Exclusive of recently raised Colonials whose numbers have not yet been
reported.

On the 9th of February the following announcement was issued


officially from the British War Office:

"In view of recent Boer activity in various directions his


Majesty's Government have decided, in addition to the large
forces recently equipped locally in South Africa, to reinforce
Lord Kitchener by 30,000 mounted troops beyond those already
landed in Cape Colony. The recruiting for Imperial Yeomanry
has proceeded so rapidly that it is anticipated not less than
10,000 will be shortly available. The South African Mounted
Constabulary, including those enlisted in the colonies, may be
relied upon to the extent of 8,000. The new colonial
contingents to replace those withdrawn will probably reach
5,000. The remainder of the force will be made up by cavalry
and mounted infantry from the home establishment. The
enlistment of Volunteer companies to replace those who have
served a year in South Africa is also being proceeded with.
Arrangements have been made for the prompt equipment and
transportation of the force."

In reply to a question in Parliament the 18th of February,


1901, Mr. Brodrick, the Secretary of State for War, stated
that the total number of cases of typhoid or enteric fever in
the British army, from the beginning of the war to the end of
December, 1900, had been 19,101; deaths 4,233; invalided and
sent home, 10,075.

SOUTH AFRICA: The Field of War: A. D. 1901 (February).


The declared policy of the British Government.

Speaking in the House of Commons on the 18th of February,


1901, the Colonial Secretary, Mr. Chamberlain, declared the
government policy of dealing with the Boers, with strong
emphasis, in the following words:

"From the moment when the invasion took place, and the first
shot was fired by the Boers, from that moment we declared our
policy, that not one shred of the independence which the Boers
had abused should ever again be conceded to them. That was the
policy stated by the Prime Minister in his answer to the
representations which were made to him by the Presidents of
the two Republics. That was the policy, is the policy, and
will be the policy of His Majesty's Government to the end. Let
there be no mistake about that. It is no use arguing with us
on the subject of independence. That, as far as we are
concerned, is a closed question. Raise it, if you like to
raise it, not in speeches, but by amendments. We are quite
ready. We challenged you at the last election. You have never
ceased to complain of the challenge. We challenge you in the
House of Commons. If you believe the annexation we have
announced ought to be repudiated; if you think, with the
honorable and learned gentleman who has just spoken, that we
ought to restore the independence of these two Republics, in
any form, it is for you to say so in a definite amendment. It
is for you to put the issue before the House of Commons and
the country and we are perfectly prepared to meet you.
Assuming that we are all agreed that annexation cannot be
undone, then the policy of the Government is to establish
equality and protection and justice for the native population
and to grant the fuller liberties involved in our definition
of self-government as soon as that can safely be conceded. …
The Boers know perfectly well, they have been told again and
again, directly and indirectly, and it has been repeatedly
stated in this House that at the earliest possible moment they
will be granted self-government."
{511}

The Liberal leader interrupted the speaker to intimate that he


understood a Crown colony government to be in contemplation,
and that his objection was to that. On which Mr. Chamberlain
proceeded to say: "Either the right honourable gentleman does
not know what Crown colony government is or else he is
quibbling about words. Will he be satisfied if I call it a
civil government, with Ministers and a Governor appointed by
his Majesty and a council to advise him? That is civil
government, and it has this about it—that the Imperial
Government has control in the last resort. That is what we
mean. … We are quite ready to establish the civil government
of which I have spoken, we are ready to maintain equality, we
are ready to secure justice to all the inhabitants of the
Transvaal and the Orange River Colony, but we are not prepared
to put into their hands the whole control of the
administration and civil government until we know it will be
safe to do so. It is said that our views have not been
communicated to the Boers and that a proclamation which I
promised I would endeavour to have circulated has not yet been
so distributed. I wish to say that, so far as the leaders are
concerned, I am convinced they know perfectly well what terms
we are willing to offer. There is no excuse on their part. It
is possible that many of their followers, being ignorant
people—when they come to us we find they have been deceived as
to what is going on—do not know the terms we are willing to
offer. We have by various means endeavoured to get to the rank
and file a knowledge of the terms which are being offered, and
we know what the result has been. The emissaries have been
sent—emissaries not sent by us, permitted by us to go, who
volunteered themselves in what they believed to be the
interests of their countrymen, to make these representations—
these emissaries have been apparently, as far as our
information goes, brutally ill-used, tortured before
execution, shot as spies after having been flogged. "
SOUTH AFRICA: The Field of War: A. D. 1901 (February).
Attitude of the English Liberal party towards the war.

See (in this volume)


ENGLAND: A. D. 1901 (FEBRUARY).

SOUTH AFRICA: The Field of War: A. D. 1901 (February-March).


Unsuccessful peace parley between Lord Kitchener and
Commandant Botha.

By the intermediation of the wife of the Boer Commandant Louis


Botha, an interview between that officer and Lord Kitchener
was brought about, on the last day of February, for discussion
"as to means of bringing the war to an end." The questions raised
in the conversation were reported by Lord Kitchener to Mr.
Brodrick, the British Secretary for War, in a telegram from
Pretoria, March 1, as follows: "I have had a long interview
with Botha, who showed very good feeling and seemed anxious to
bring about peace. He asked for information on a number of
subjects which he said that he should submit to his Government
and people, and if they agreed he should visit Orange River
Colony and get them to agree. They should all then hand in
their arms and finish the war. He told me that they could go
on for some time, and that he was not sure of being able to
bring about peace without independence. He tried very hard for
some kind of independence, but I declined to discuss such a
point, and said that a modified form of independence would be
most dangerous and likely to lead to war in the future.
Subject was then dropped, and—

"Firstly.—The nature of future government of Colonies asked


about. He wanted more details than were given by Colonial
Secretary, and I said that, subject to correction from home, I
understood that when hostilities ceased military guard would be
replaced by Crown Colony administration, consisting of
nominated Executive, with elected assembly to advise
administration, to be followed after a period by
representative government. He would have liked representative
government at once, but seemed satisfied with above.

"Secondly.—Whether a Boer would be able to have a rifle to


protect him from native? I said I thought he would be by a
licence and on registration.

"Thirdly.—He asked whether Dutch language would be allowed? I


said that English and Dutch would, I thought, have equal
rights. He expressed hope that officials dealing with farmers
would know Dutch.

"Fourthly.—The Kaffir question. This turned at once on


franchise of Kaffirs, and a solution seemed to be that
franchise should not be given to Kaffirs until after
representative government was granted to Colonies. Orange Free
State laws for Kaffirs were considered good.

"Fifthly.—That Dutch Church property should remain untouched.

"Sixthly.—Public trusts and orphan funds to be left intact. He


asked whether British Government, in taking over the assets of
Republics, would also take over legal debts. This he made
rather a strong point of, and he intended it to include debts
legally contracted since the war began. He referred to notes
issued amounting to less than a million.

"Seventhly.—He asked if any war tax would be imposed on


farmers? I said I thought not.

"Eighthly.—When would prisoners of war return?

"Ninthly.—He referred to pecuniary assistance to repair burnt


farms, and enable fanners to start afresh. I said I thought
some assistance would be given.
"Tenthly.—Amnesty to all at end of war. We spoke of Colonials
who joined Republics, and he seemed not adverse to their being
disfranchised.

"I arranged with him that I should write and let him know the
view of the Government on these points. All I said during the
interview was qualified by being subject to confirmation from
home. He was anxious to get an answer soon."

Two days later, General Kitchener drafted and submitted to


High Commissioner Sir A. Milner the reply which he wished to
be authorized to make to the questions of Commandant Botha.
This was transmitted, in turn, by the High Commissioner to
Colonial Secretary Chamberlain, with approval of all the
suggestions of Lord Kitchener, except on the subject of
amnesty to the rebel "Afrikanders" of Cape Colony and Natal,
who had joined the ranks of the Boers. Lord Kitchener wished
to say that "on the cessation of hostilities and the complete
surrender of arms, ammunition, cannon, and other munitions of
war now in the hands of the burghers in the field or in
Government depots or elsewhere, His Majesty's Government is
prepared at once to grant an amnesty in the Transvaal and
Orange River Colony for all bona fide acts of war committed
during the recent hostilities; as well as to move the
Governments of Cape Colony and Natal to take similar action
but qualified by the disfranchisement of any British subjects
implicated in the recent war."
{512}
Sir Alfred Milner proposed to amend the latter clause as
follows: "British subjects of Cape Colony or Natal, though
they will not be compelled to return to those Colonies, will,
if they do so, be liable to be dealt with under the laws of
those Colonies specifically passed to meet the circumstances
arising out of the present war and which greatly mitigate the
ordinary penalties of rebellion." "While willing," he said,
"to concede much in order to strengthen Botha in inducing his
people to submit, the amnesty of rebels is not, in my opinion,

You might also like