100% found this document useful (1 vote)
12 views

Instant Access to Learn Programming with C: An Easy Step-by-Step Self-Practice Book for Learning C 1st Edition Imran ebook Full Chapters

Easy

Uploaded by

fowzilubbuu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
12 views

Instant Access to Learn Programming with C: An Easy Step-by-Step Self-Practice Book for Learning C 1st Edition Imran ebook Full Chapters

Easy

Uploaded by

fowzilubbuu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

Download the full version of the ebook at

https://ebookmass.com

Learn Programming with C: An Easy Step-by-


Step Self-Practice Book for Learning C 1st
Edition Imran

https://ebookmass.com/product/learn-programming-
with-c-an-easy-step-by-step-self-practice-book-
for-learning-c-1st-edition-imran/

Explore and download more ebook at https://ebookmass.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Microsoft Visual C# Step by Step, 9th Edition John Sharp

https://ebookmass.com/product/microsoft-visual-c-step-by-step-9th-
edition-john-sharp/

testbankdeal.com

Microsoft Visual C# Step by Step 10th Edition John Sharp

https://ebookmass.com/product/microsoft-visual-c-step-by-step-10th-
edition-john-sharp/

testbankdeal.com

Python Programming for Beginners: 2 Books in 1 - the


Ultimate Step-By-Step Guide to Learn Python Programming
Quickly With Practical Exercises Mark Reed
https://ebookmass.com/product/python-programming-for-
beginners-2-books-in-1-the-ultimate-step-by-step-guide-to-learn-
python-programming-quickly-with-practical-exercises-mark-reed/
testbankdeal.com

Easy Algebra Step-by-Step, Third Edition Sandra Luna


Mccune

https://ebookmass.com/product/easy-algebra-step-by-step-third-edition-
sandra-luna-mccune/

testbankdeal.com
McGraw-Hill's easy English step-by-step for ESL Learners.
Student Book. 2nd Edition Danielle Pelletier

https://ebookmass.com/product/mcgraw-hills-easy-english-step-by-step-
for-esl-learners-student-book-2nd-edition-danielle-pelletier/

testbankdeal.com

Learn Data Mining Through Excel: A Step-by-Step Approach


for Understanding Machine Learning Methods, 2nd Edition
Hong Zhou
https://ebookmass.com/product/learn-data-mining-through-excel-a-step-
by-step-approach-for-understanding-machine-learning-methods-2nd-
edition-hong-zhou/
testbankdeal.com

Python Programming: 3 Books in 1: Ultimate Beginneru2019s,


Intermediate & Advanced Guide to Learn Python Step-by-Step

https://ebookmass.com/product/python-programming-3-books-
in-1-ultimate-beginners-intermediate-advanced-guide-to-learn-python-
step-by-step/
testbankdeal.com

Game Theory: An Introduction with Step-by-Step Examples


Ana Espinola-Arredondo

https://ebookmass.com/product/game-theory-an-introduction-with-step-
by-step-examples-ana-espinola-arredondo/

testbankdeal.com

Microsoft Project 2019 Step by Step (Step by Step


(Microsoft)) Cindy Lewis & Carl Chatfield & Timothy
Johnson [Lewis
https://ebookmass.com/product/microsoft-project-2019-step-by-step-
step-by-step-microsoft-cindy-lewis-carl-chatfield-timothy-johnson-
lewis/
testbankdeal.com
Learn Programming with C

Authored by two standout professors in the feld of Computer Science and Technology
with extensive experience in instructing, Learn Programming with C: An Easy Step-by Step
Self-Practice Book for Learning C is a comprehensive and accessible guide to programming
with one of the most popular languages.
Meticulously illustrated with fgures and examples, this book is a comprehensive
guide to writing, editing, and executing C programs on diferent operating systems and
platforms, as well as how to embed C programs into other applications and how to create
one’s own library. A variety of questions and exercises are included in each chapter to test
the readers’ knowledge.
Written for the novice C programmer, especially undergraduate and graduate students,
this book’s line-by-line explanation of code and succinct writing style makes it an excellent
companion for classroom teaching, learning, and programming labs.

Sazzad M.S. Imran, Ph.D., is Professor in the Department of Electrical and Electronic
Engineering, University of Dhaka, Bangladesh. He completed his B.Sc. and M.S. degrees in
Applied Physics, Electronics & Communication Engineering from the University of Dhaka
and received his Ph.D. degree from the Optical Communication Lab of the Kanazawa
University, Japan. Dr. Imran has vast experience in teaching C/C++, Assembly Language,
MATLAB®, PSpice, AutoCAD, etc., at the university level (more at sazzadmsi.webnode.
com).

Md Atiqur Rahman Ahad, Ph.D., SMIEEE, SMOPTICA, is Associate Professor of


Artifcial Intelligence and Machine Learning at the University of East London, UK; and
Visiting Professor at the Kyushu Institute of Technology, Japan. He worked as Professor at
the University of Dhaka and Specially Appointed Associate Professor at Osaka University.
He has authored/edited 14+ books and published 200+ peer-reviewed papers (more at
http://ahadvisionlab.com).
Learn Programming with C
An Easy Step-by-Step Self-Practice Book
for Learning C

Sazzad M.S. Imran, Ph.D.


Md Atiqur Rahman Ahad, Ph.D.
MATLAB® is a trademark of The MathWorks, Inc. and is used with permission. The MathWorks does not warrant the
accuracy of the text or exercises in this book. This book’s use or discussion of MATLAB® software or related products
does not constitute endorsement or sponsorship by The MathWorks of a particular pedagogical approach or particular
use of the MATLAB® software.
First edition published 2024
by CRC Press
2385 NW Executive Center Drive, Suite 320, Boca Raton FL 33431
and by CRC Press
4 Park Square, Milton Park, Abingdon, Oxon, OX14 4RN
CRC Press is an imprint of Taylor & Francis Group, LLC
© 2024 Prof. Sazzad M.S. Imran, Ph.D. and Prof. Md Atiqur Rahman Ahad, Ph.D.
Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot
assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers
have attempted to trace the copyright holders of all material reproduced in this publication and apologize to
copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been
acknowledged please write and let us know so we may rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or
utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including
photocopying, microfilming, and recording, or in any information storage or retrieval system, without written
permission from the publishers.
For permission to photocopy or use material electronically from this work, access www.copyright.com or contact the
Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978–750–8400. For works that
are not available on CCC please contact [email protected]
Trademark notice: Product or corporate names may be trademarks or registered trademarks and are used only for
identification and explanation without intent to infringe.
Library of Congress Cataloging-in-Publication Data
Names: Imran, Sazzad, author. | Ahad, Md. Atiqur Rahman, author.
Title: Learn programming with C / Prof. Sazzad Imran, Ph.D, and Prof. Md. Atiqur Rahman Ahad, Ph.D.
Description: First edition. | Boca Raton, FL : CRC Press, 2024. | Includes bibliographical references and index. |
Summary: “Authored by two standout professors in the fields of Computer Science and Technology with
extensive experience in instructing, Learn Programming with C is a comprehensive and accessible guide to
programming with one of the most popular languages. Meticulously illustrated with figures and examples, this
book is a comprehensive guide to writing, editing and executing C programs on different operating systems and
platforms, as well as how to embed C programs into other applications and how to create one’s own library.
A variety of questions and exercises are included in each chapter to test the readers’ knowledge Written for the
novice C programmer, especially undergraduate and graduate students, this book’s line-by-line explanation of
code and succinct writing style makes it an excellent companion for classroom teaching, learning and
programming labs”—Provided by publisher.
Identifiers: LCCN 2023033790 (print) | LCCN 2023033791 (ebook) | ISBN 9781032299082 (hbk) |
ISBN 9781032283555 (pbk) | ISBN 9781003302629 (ebk)
Subjects: LCSH: C (Computer program language). | Computer programming.
Classification: LCC QA76.73.C15 I47 2024 (print) | LCC QA76.73.C15 (ebook) | DDC 005.13/3—dc23/eng/20231026
LC record available at https://lccn.loc.gov/2023033790
LC ebook record available at https://lccn.loc.gov/2023033791
ISBN: 9781032299082 (hbk)
ISBN: 9781032283555 (pbk)
ISBN: 9781003302629 (ebk)
DOI: 10.1201/9781003302629
Typeset in Minion
by Apex CoVantage, LLC
Access the Support Material: www.routledge.com/learn-programming-with-c/ahad/p/book/9781032299082
Contents

Preface, xi

CHAPTER 1 ◾ Introduction 1
1.1 HISTORY OF PROGRAMMING LANGUAGE 1
1.2 DIFFERENT TYPES OF PROGRAMMING LANGUAGE 2
1.3 IMPORTANCE OF PROGRAMMING 3
1.4 C PROGRAM STRUCTURE 3
1.5 STEP-BY-STEP TUTORIAL TO RUN A C PROGRAM 5
1.6 KEYWORDS 7
1.7 IDENTIFIERS 7
1.8 OPERATORS 8
1.9 OPERATOR PRECEDENCE IN C 9
1.10 VARIABLES 9
1.11 CONSTANTS 10
1.12 ESCAPE SEQUENCES 10
1.13 DATA TYPES 10
1.14 TYPE CASTING 11
1.15 EXAMPLES 12
EXERCISES 26
– MCQ with Answers 26
– Questions with Short Answers 37
– Problems to Practice 44

CHAPTER 2 ◾ Flow Control 46


2.1 IF STATEMENT 46
2.2 IF..ELSE STATEMENT 47
2.3 NESTED IF..ELSE STATEMENT 47
2.4 CONDITIONAL OPERATOR 48

v
vi ◾ Contents

2.5 FOR LOOP 49


2.6 WHILE LOOP 51
2.7 DO..WHILE LOOP 52
2.8 CONTINUE STATEMENT 53
2.9 BREAK STATEMENT 53
2.10 SWITCH..CASE STATEMENT 54
2.11 GOTO STATEMENT 55
2.12 EXAMPLES 56
EXERCISES 140
– MCQ with Answers 140
– Questions with Short Answers 143
– Problems to Practice 149

CHAPTER 3 ◾ Arrays and Pointers 152


3.1 ARRAYS 152
3.2 2D ARRAYS 153
3.3 MULTIDIMENSIONAL ARRAYS 154
3.4 STRING 155
3.5 STRING FUNCTIONS 155
3.6 POINTERS 156
3.7 MEMORY ALLOCATION 156
3.8 EXAMPLES 157
EXERCISES 205
– MCQ with Answers 205
– Questions with Short Answers 211
– Problems to Practice 214

CHAPTER 4 ◾ Functions 217


4.1 FUNCTION TYPES 217
4.2 FUNCTION STRUCTURE 217
4.3 FUNCTION CALL 218
4.4 ARRAYS AND FUNCTIONS 218
4.5 POINTERS AND FUNCTIONS 218
4.6 STORAGE CLASS 219
4.7 EXAMPLES 219
Contents ◾ vii

EXERCISES 294
– MCQ with Answers 294
– Questions with Short Answers 296
– Problems to Practice 299

CHAPTER 5 ◾ Structure and Union 301


5.1 STRUCTURE 301
5.2 UNION 302
5.3 ENUM 302
5.4 DATA STRUCTURE AND ALGORITHM 303
5.5 LINKED LIST 304
5.6 TYPES OF LINKED LIST 305
5.7 EXAMPLES 306
EXERCISES 426
– MCQ with Answers 426
– Questions with Short Answers 430
– Problems to Practice 433

CHAPTER 6 ◾ File Management 437


6.1 FILE TYPES 437
6.2 FILE OPERATIONS 437
6.3 PREPROCESSORS 439
6.4 CONDITIONAL COMPILATION 439
6.5 EXAMPLES 440
EXERCISES 472
– MCQ with Answers 472
– Questions with Short Answers 474
– Problems to Practice 475

CHAPTER 7 ◾ C Graphics 477


7.1 INTRODUCTION 477
7.2 FUNCTION 477
7.3 COLOR TABLE 478
7.4 FONTS OF TEXT 479
7.5 FILL PATTERNS 479
7.6 INCLUDING GRAPHICS.H IN CODEBLOCKS 480
viii ◾ Contents

7.7 EXAMPLES 480


Problems to Practice 513

CHAPTER 8 ◾ C Cross-platform 515


8.1 CREATING OWN LIBRARY 515
8.1.1 Creating Static Library 515
8.1.2 Creating Dynamic Library 519
8.2 TURBO C 522
8.3 VISUAL STUDIO CODE 525
8.4 VISUAL STUDIO 529
8.5 COMMAND LINE 531
8.6 COMMAND LINE ARGUMENTS 534
8.7 LINUX 537
8.8 EMBEDDING C CODE INTO MATLAB 539
Using MinGW-W64 Compiler 539
Using S-Function Builder 541
Using C Function Block 545
Using C Caller Block 549
8.9 INTEGRATING C CODE INTO PYTHON 552
8.10 SWITCHING FROM ONE LANGUAGE TO ANOTHER 555
8.11 TRANSITION TO C++ OR C# FROM C 557

CHAPTER 9 ◾ C Projects 558


PROJECT-1 558
PROJECT-2 558
PROJECT-3 558
PROJECT-4 558
PROJECT-5 559
PROJECT-6 559
PROJECT-7 559
PROJECT-8 559
PROJECT-9 559
PROJECT-10 559
PROJECT-10 560
PROJECT-11 560
PROJECT-12 560
Visit https://ebookmass.com
now to explore a rich
collection of eBooks and enjoy
exciting offers!
Contents ◾ ix

PROJECT-13 560
PROJECT-14 560
PROJECT-15 560
PROJECT-16 560
PROJECT-17 560
PROJECT-18 561
PROJECT-19 561
PROJECT-20 561
PROJECT-21 561
PROJECT-22 561
INDEX, 563
Preface

C is a programming language with which every sofware developer should become


familiar. Tough numerous books are available on C programming language, most
of the example programs are written without algorithms or any fowchart in those books.
As a result, it becomes difcult for a student to comprehend the core of a programming
language through a self-learning approach. Our experience in teaching C underscores the
importance of presenting C programs by the fowchart solution frst, then the pseudocode
solution, and fnally the actual C code with the line-by-line explanation.
It is written for C programming language courses/modules at the undergraduate and
graduate levels – mostly for beginners. However, if one has prior knowledge on program-
ming, one may skip the initial couple of chapters. By going through this book, any student
or a beginner can learn and understand C programming by taking only a little or no help
from an instructor. For the instructors, this book is an easy guidance. Only going through
this book will be sufcient for them to teach C programming – as theory lectures and prac-
tical lab. We avoid a broad or overly verbose presentation or information overload, and the
book presents a concise and defnitive perspective to C.
Tis book is written as a self-practice book for learning programming by going through
all the detailed problem solutions and working through the pseudocode, fowchart, and
the actual code. In addition, readers can observe a clearer correlation between the indi-
vidual steps in the pseudocode and the fowchart itself for a better understanding of the
program fow.
One of the specialties of this book is that we introduce a new chapter that illustrates
on writing and running C codes under various operating systems and platforms. How to
embed C codes into other applications is also presented. Each chapter incorporates a num-
ber of relevant inquisitive questions and their corresponding answers. A variety of good
exercises are also available in the textbook. Another original incorporation of this book
is the last chapter, where a number of large projects are presented for students to explore
comprehensiveness in the C programming language.
Source codes for all programs in this book will be available for those who will purchase
the book. Tough we worked hard to ensure the perfection of this book, it may have issues
that require amendments. Terefore, please feel free to share at [email protected] and
[email protected].

xi
xii ◾ Preface

In conclusion, this book is a guided self-study for those interested in learning C by fol-
lowing a detailed, tutorial-type problem-solving book. We feel that it is a great book for
teachers to cover as a textbook for C programming language.

Prof. Sazzad M.S. Imran, Ph.D.


Prof. Md Atiqur Rahman Ahad, Ph.D.

MATLAB® is a registered trademark of Te Math Works, Inc. For product information,


please contact:
Te Math Works, Inc.
3 Apple Hill Drive
Natick, MA 01760-2098
Tel: 508-647-7000
Fax: 508-647-7001
E-mail: [email protected]
Web: http://www.mathworks.com
CHAPTER 1

Introduction

C is a machine-independent, efficient, easy-to-use structured programming lan-


guage used to create various applications, operating systems, and sophisticated pro-
grams. C is widely recognized as the foundation of programming language, implying that
anyone who understands C can quickly acquire or grasp other structured programming
languages. Dennis Ritchie, a computer scientist at the Bell Laboratories in the United
States, designed the C programming language in 1972.

1.1 HISTORY OF PROGRAMMING LANGUAGE


Ada Lovelace created the first programming language in 1843 for an early computing sys-
tem. She created the first machine algorithm for the Difference Machine of Charles Babbage.
However, Konrad Zuse created the first proper programming language, Plankalkul, often
known as plan calculus, sometime between 1944 and 1945. After that, in 1947, Kathleen
Booth devised assembly language, a low-level programming language that simplified
machine coding. John McCauley proposed the first high-level language, Shortcode or
Short-order-code, in 1949. Alick Glennie created the first compiled language, Autocode,
for the Mark 1 computer in 1952.
John Backus invented FORmula TRANslation, or FORTRAN, in 1957. It was designed
for complex scientific, mathematical, and statistical calculations and is still used today.
A group of American and European computer scientists collaborated to create ALGOL,
or algorithmic language, in 1958. In the same year, John McCarthy of MIT proposed the
LISP (list processing) programming language for artificial intelligence. Dr. Grace Murray
Hopper oversaw the development of COBOL (Common Business Oriented Language) in
1959, which was created for credit card processors, ATMs, telephone and mobile phone
calls, hospital signals, traffic signal systems, and banking systems.
Beginners All-purpose Symbolic Instruction Code, or BASIC, was created in 1964 by
Dartmouth College students and later improved by Microsoft founders Bill Gates and Paul
Allen. The PASCAL was created in 1970 by Niklaus Wirth in honor of French mathemati-
cian Blaise Pascal. It was the first choice of Apple because of its simplicity of use and power.
Alan Kay, Adele Goldberg, and Dan Ingalls of the Xerox Palo Alto Research Centre created

DOI: 10.1201/9781003302629-1 1
2 ◾ Learn Programming with C

Smalltalk in 1972. Leafy, Logitech, and CrowdStrike were among the companies that used
it. In the same year, Dennis Ritchie created C for use with the Unix operating system at Bell
Telephone Laboratories. C is the basis for several modern languages, including C#, Java,
JavaScript, Perl, PHP, and Python. In 1972, IBM researchers Raymond Boyce and Donald
Chamberlain created SQL, which stood for Structured Query Language. It is a program
that lets you explore and edit data stored in databases.
Afer mathematician Ada Lovelace, Ada was created in 1980–1981 by a team directed
by Jean Ichbiah of CUU Honeywell Bull. Ada is an organized, statically typed, imperative,
wide-spectrum, and object-oriented high-level programming language used for air trafc
control systems. Bjarne Stroustrup created C++ afer modifying the C language at Bell
Labs in 1983. C++ is a high-performance programming language used in Microsof Ofce,
Adobe Photoshop, game engines, and other high-performance sofware. Brad Cox and
Tom Love created the Objective-C programming language in 1983 to construct sofware
for macOS and iOS. Larry Wall designed Perl in 1987 as a general-purpose, high-level pro-
gramming language for text editing.
Haskell, a general-purpose programming language, was created in 1990 to deal with
complex calculations, records, and number crunching. Guido Van Rossum created the
general-purpose, high-level programming language Python in 1991, and it is used by
Google, Yahoo, and Spotify. Visual Basic is a programming language created by Microsof
in 1991 that allows programmers to use a graphical user interface and is used in vari-
ous applications such as Word, Excel, and Access. Yukihiro Matsumoto designed Ruby
in 1993 as an interpreted high-level language for web application development. James
Gosling designed Java in 1995 as a general-purpose, high-level programming language
with cross-platform capabilities. Rasmus Lerdorf created the hypertext preprocessor PHP
in 1995 to create and maintain dynamic web pages and server-side applications. Brendan
Eich wrote JavaScript in 1995 for desktop widgets, dynamic web development, and PDF
documents.
Microsof created C# in 2000 by combining the computing power of C++ with the sim-
plicity of Visual Basic. Almost every Microsof product currently uses C#. In 2003, Martin
Odersky created Scala, which combines functional mathematical and object-oriented pro-
gramming. Scala is a Java-compatible programming language that is useful in Android
development. In 2003, James Strachan and Bob McWhirter created Groovy, a concise and
easy-to-learn language derived from Java. Google created Go in 2009, and it has since
gained popularity among Uber, Twitch, and Dropbox. Apple created Swif in 2014 to
replace C, C++, and Objective-C for desktop, mobile, and cloud applications.

1.2 DIFFERENT TYPES OF PROGRAMMING LANGUAGE


To communicate with computers, programmers utilize a programming language. Tere
are three broad categories of computer languages:

(a) Machine language


Referred to as machine code or object code, a set of binary digits 0 and 1. Easily
understandable by computer systems but not by users.
Introduction ◾ 3

(b) Assembly language


Considered a low-level language and used to implement the symbolic representa-
tion of machine codes.
(c) High-level language
Easy to understand and code by users. Not understandable by computer systems,
hence needs to be transformed into machine code. Diferent types of high-level
languages are as follows:
(i) Algorithmic languages – FORTRAN, ALGOL, C
(ii) Business-oriented languages – COBOL, SQL
(iii) Education-oriented languages – BASIC, Pascal, Logo, Hypertalk
(iv) Object-oriented languages – C++, C#, Ada, Java, Visual Basic, Python
(v) Declarative languages – PROLOG, LISP
(vi) Scripting languages – Perl
(vii) Document formatting languages – TeX, PostScript, SGML
(viii) World Wide Web display languages – HTML, XML
(ix) Web scripting languages – JavaScript, VB Script

1.3 IMPORTANCE OF PROGRAMMING


In recent years, programming has become the most in-demand skill. From smart TVs to
kitchen appliances, technological disruption is evident practically everywhere. As a result,
many new employments are created, and a large number of current jobs are redefned.
Programming skills provide a competitive advantage in a variety of career felds. As a
result, it is undoubtedly one of the most crucial talents to learn for both present and future
generations.
Programming helps us think more logically and analytically. Students who learn pro-
gramming languages at an early age will have many career options in the future. It is no
longer a choice to learn but rather a necessary talent to master. Apart from sofware and
application development, business analysts, graphic artists, and data scientists are among
the occupations that require programming knowledge.

1.4 C PROGRAM STRUCTURE


Te source code of any C program is written according to the syntax of the computer lan-
guage. Te source code for a C program can be written in any text editor and then saved
with the .c extension, for example, flename.c. Any alpha-numeric character, including
underscores, can be used in the fle name, except we cannot use any keyword as a fle name.
Afer then, any standard C compiler, such as Turbo C or CodeBlocks, is used to compile
and run the source code fle. Let us get started with the frst C program.
4 ◾ Learn Programming with C

Input and Output:

Explanation of the program:


Comment: Any comment in a C program begins with ‘/*’ and ends with ‘*/’. // can also
be used to make a single-line comment. Tough it is not required to write comments, it is a
good practice to do so in order to improve the readability of the program. Tere can be any
number of comments placed anywhere in the program, as the comments are not executed.
include: Many keywords and library functions, such as printf() and scanf(), may be required
in any C program. stdio.h, conio.h, and other header fles contain prototypes or declarations of
the library functions that must be included in the program. Te header fle stdio.h is included
in this program. It provides declarations for the functions printf() that displays data on the
standard output terminal and scanf() that reads data from the standard input terminal.
Display: Te built-in library function printf() displays anything written inside double
quotation marks on the output console. Te values of the variables can also be displayed
using the format specifers.
User input: Te C library function scanf() takes input from the input terminal. Following
the program’s execution, the input console awaits input, and once the age is entered, the
remaining statements are executed based on the age input.
main() function: Te main() function is used to start executing any C program source
code; hence, every C program must have one. Te main() function has the following struc-
ture. Te function name is followed by the return type, which can be either int or void.
Te return type is required for the compiler to determine if the program was successfully
compiled or not. We return 0 at the end of the main() function as 0 is the standard for
the “successful execution of the program”. Also, the ANSI standard does not allow using
void main(); therefore, it is preferred to use ‘int main()’ over ‘void main()’. If there are any
Introduction ◾ 5

arguments or parameters afer the function name, they are enclosed in parentheses; other-
wise, they are lef empty. Te body of the main() function is comprised of all the statements
between the opening and closing curly braces.

1.5 STEP-BY-STEP TUTORIAL TO RUN A C PROGRAM


We use Code::Blocks for windows OS to run all the programs available in this book. It is
a free, open-source, cross-platform C IDE built to meet the most demanding needs of its
users. How to run the programs using other compilers, platforms, or operating systems is
available in Chapter 8.
A step-by-step tutorial to run any C program using Code::Blocks is given below.

Step-1: Visit www.codeblocks.org/downloads/binaries/; download, and install code-


blocks-20.03mingw-32bit-setup.exe. We prefer 32-bit with mingw package as
that version is compatible with graphics.h header fle necessary for C graphics
programs.

Step-2: Open Code::Blocks and click on File→New→Project . . ., select ‘Empty project’


and click on Go and then Next>.

Write C-Program (or any name of your choice) on the ‘Project title:’ and choose the
folder (for example, C:\Users\SazzadImran\Desktop\) where you want to create the
project. Click Next>→Finish. A project or folder is created on the desktop.
Visit https://ebookmass.com
now to explore a rich
collection of eBooks and enjoy
exciting offers!
6 ◾ Learn Programming with C

Step-3: Double click on C-Program on Workspace to select the project and click
File→New→Empty fle→Yes. Write a fle name of your choice (Example-1, for example)
and click Save.

Check Debug and Release and then press OK.

An empty fle name Example-1.c is created and saved in the C-Program folder.
Step-4: Write your C program codes on the fle Example-1.c and save the fle.
Introduction ◾ 7

Step-5: Click Build→‘Compile current fle’ to compile the program. Correct any error(s)
or warning(s) on the codes. Correcting the errors is a must though it is optional to
correct the warnings. Recompile the program until we get 0 error(s) and 0 warning(s).

Step-6: Click Build→‘Build and run’ to execute the program. Te output screen will look
as follows:

1.6 KEYWORDS
In C programming, 32 reserved words have special meaning to compilers and are utilized
as a part of the syntax. Tese terms cannot be used as names or identifers for variables. Te
list of reserved C keywords is as follows:
auto, break, case, char, const, continue, default, do, int, long, register, return, short,
signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while, double,
else, enum, extern, foat, for, goto, if.

1.7 IDENTIFIERS
Variables, functions, structures, and other objects in a program are given unique names
called identifers. For example, in the statement of the preceding demo program

int age;

int is a keyword and age is an identifer assigned to a variable by the compiler to iden-
tify the entity uniquely. When naming an identifer, the following guidelines should be
observed.

(1) A valid identifer can include uppercase and lowercase letters, numbers, and
underscores.
(2) Te frst character cannot be a digit.
(3) We cannot use any keyword as an identifer.
(4) Te length of the identifer is unlimited.

It is a good practice to give the identifer a meaningful name.


Random documents with unrelated
content Scribd suggests to you:
“No, my nephew, I take you for a wise man—who understands that
his dear aunt will not buy those interesting forgeries, perpetrated by
Monsieur le Marquis Amédé de Terhoven, and offered to her by
Rubinstein the money-lender, unless that confession is written and
signed by you. Write Amédé, write that confession, my dear nephew,
if you do not wish to see yourself in the dock on a charge of forging
your aunt’s name to a bill for one hundred thousand francs.”
Amédé muttered a curse between his teeth. Obviously the old
woman’s shaft had struck home. He knew himself to be in a
hopeless plight. It appears that a money-lender had threatened to
send the forged bills to Monsieur le Procureur de la République
unless they were paid within twenty-four hours, and no one could
pay them but Miss de Genneville, who had refused to do it except at
the price of this humiliating confession.
A look of intelligence passed between mother and son. Intercepted
by Lady Molly and interpreted by her, it seemed to suggest the idea
of humouring the old aunt, for the moment, until the forgeries were
safely out of the money-lender’s hands, then of mollifying her later
on, when perhaps she would have forgotten, or sunk deeper into
helplessness and imbecility.
As if in answer to his mother’s look the young man now said curtly:
“I must know what use you mean to make of the confession if I do
write it.”
“That will depend on yourself,” replied Mademoiselle, dryly. “You
may be sure that I will not willingly send my own nephew to penal
servitude.”
For another moment the young man hesitated, then he sat down,
sullen and wrathful, and said:
“I’ll write—you may dictate——”
The old woman laughed a short, dry, sarcastic laugh. Then, at her
dictation, Amédé wrote:

“I, Amédé, Marquis de Terhoven, hereby make confession


to having forged Mademoiselle Angela de Genneville’s name
to the annexed bills, thereby obtaining the sum of one
hundred thousand francs from Abraham Rubinstein, of Brest.”
“Now, Monsieur le Curé, will you kindly witness le Marquis’
signature?” said the irascible old lady when Amédé had finished
writing; “and you, too, my dear?” she added, turning to Lady Molly.
My dear lady hesitated for a moment. Naturally she did not desire
to be thus mixed up in this family feud, but a strange impulse had
drawn her sympathy to this eccentric old lady, who, in the midst of
her semi-regal splendour seemed so forlorn, between her nephew,
who was a criminal and a blackguard, and her sister, who was but
little less contemptible.
Obeying this impulse, and also a look of entreaty from the Curé,
she affixed her own signature as witness to the document, and this
despite the fact that both the Marquise and her son threw her a look
of hate which might have made a weaker spirit tremble with
foreboding.
Not so Lady Molly. Those very same threatening looks served but
to decide her. Then, at Mademoiselle’s command, she folded up the
document, slipped it into an envelope, sealed it, and finally
addressed it to M. le Procureur de la République, resident at Caen.
Amédé watched all these proceedings with eyes that were burning
with impotent wrath.
“This letter,” now resumed the old lady, more calmly, “will be sent
under cover to my lawyer, Maître Vendôme, of Paris, who drew up
my will, with orders only to post it in case of certain eventualities,
which I will explain later on. In the meanwhile, my dear nephew, you
may apprise your friend, Abraham Rubinstein, that I will buy back
those interesting forgeries of yours the day on which I hear from
Maître Vendôme that he has safely received my letter with this
enclosure.”
“This is infamous——” here broke in the Marquise, rising in full
wrath, unable to control herself any longer. “I’ll have you put under
restraint as a dangerous lunatic. I——”
“Then, of course, I could not buy back the bills from Rubinstein,”
rejoined Mademoiselle, calmly.
Then, as the Marquise subsided—cowed, terrified, realising the
hopelessness of her son’s position—the old lady turned placidly to
my dear lady, whilst her trembling fingers once more clutched the
slender hand of her newly found English friend.
“I have asked you, my dear, and Monsieur le Curé, to come to me
to-day,” she said, “because I wish you both to be of assistance to me
in the carrying out of my dying wishes. You must promise me most
solemnly, both of you, that when I am dead you will carry out these
wishes to the letter. Promise!” she added with passionate
earnestness.
The promise was duly given by Lady Molly and the old Curé, then
Mademoiselle resumed more calmly:
“And now I want you to look at that clock,” she said abruptly, with
seeming irrelevance. “It is an old heirloom which belonged to the
former owners of Porhoët, and which I bought along with the house.
You will notice that it is one of the most remarkable pieces of
mechanism which brain of man has ever devised, for it has this great
peculiarity, that it goes for three hundred and sixty-six days
consecutively, keeping most perfect time. When the works have all
but run down, the weights—which are enormous—release a certain
spring, and the great doors of the case open of themselves, thus
allowing the clock to be wound up. After that is done, and the doors
pushed to again, no one can open them until another three hundred
and sixty-six days have gone by—that is to say, not without breaking
the case to pieces.”
Lady Molly examined the curious old clock with great attention.
Vaguely she guessed already what the drift of the old lady’s curious
explanations would be.
“Two days ago,” continued Mademoiselle, “the clock was open,
and Monsieur le Curé wound it up, but before I pushed the doors to
again I slipped certain papers into the case—you remember,
Monsieur?”
“Yes, Mademoiselle, I remember,” responded the old man.
“Those papers were my last will and testament, bequeathing all I
possess to the parish of Porhoët,” said Miss de Genneville, dryly,
“and now the doors of the massive case are closed. No one can get
at my will for another three hundred and sixty-four days—no one,”
she added with a shrill laugh, “not even my nephew, Amédé de
Terhoven.”
A silence ensued, only broken by the rustle of Madame la
Marquise’s silk dress as she shrugged her shoulders and gave a
short, sarcastic chuckle.
“My dear,” resumed Mademoiselle, looking straight into Lady
Molly’s eager, glowing face, “you must promise me that, three
hundred and sixty-four days hence, that is to say on the 20th
September next year, you and Monsieur le Curé—or one of you if the
other be incapacitated—will be present in this room at this hour
when the door of the clock will open. You will then wind up the family
heirloom, take out the papers which you will find buried beneath the
weights, and hand them over to Maître Vendôme for probate at the
earliest opportunity. Monseigneur the Bishop of Caen, the Mayor of
this Commune, and the Souspréfet of this Department have all been
informed of the contents of my will, and also that it is practically in
the keeping of le Curé de Porhoët, who, no doubt, realises what the
serious consequences to himself would be if he failed to produce the
will at the necessary time.”
The poor Curé gasped with terror.
“But—but—but——” he stammered meekly, “I may be forcibly
prevented from entering the house—I might be ill or——”
He shuddered with an unavowable fear, then added more calmly:
“I might be unjustly accused then of stealing the will—of
defrauding the poor of Porhoët in favour of—Mademoiselle’s direct
heirs.”
“Have no fear, my good friend,” said Mademoiselle, dryly; “though I
have one foot in the grave I am not quite so imbecile as my dear
sister and nephew here would suggest, and I have provided for
every eventuality. If you are ill or otherwise prevented by outside
causes from being present here on the day and hour named, this
charming English lady will be able to replace you. But if either of you
is forcibly prevented from entering this house, or if, having entered
this room, the slightest violence or even pressure is put upon you, or
if you should find the clock broken, damaged and—stripped of its
contents, all you need do is to apprise Maître Vendôme of the fact.
He will know how to act.”
“What would he do?”
“Send a certain confession we all know of to Monsieur le
Procureur de la République,” replied the old lady, fixing the young
Marquis Amédé with her irascible eye. “That same confession,” she
continued lightly, “Maître Vendôme is instructed to destroy if you,
Monsieur, and my English friend here, and the clock, are all
undamaged on the eventful day.”
There was silence in the great, dark room for awhile, broken only
by the sarcastic chuckle of the enfeebled invalid, tired out after this
harrowing scene, wherein she had pitted her half-maniacal ingenuity
against the greed and rapacity of a conscienceless roué.
That she had hemmed her nephew and sister in on every side
could not be denied. Lady Molly herself felt somewhat awed at this
weird revenge conceived by the outraged old lady against her
grasping relatives.
She was far too interested in the whole drama to give up her own
part in it, and, as she subsequently explained to me, she felt it her
duty to remain the partner and co-worker of the poor Curé in this
dangerous task of securing to the poor of Porhoët the fortune which
otherwise would be squandered away on gaming tables and race-
courses.
For this, and many reasons too complicated to analyse, she
decided to accept her share in the trust imposed upon her by her
newly-found friend.
Neither the Marquise nor her son took any notice of Lady Molly as
she presently took leave of Mademoiselle de Genneville, who, at the
last, made her take a solemn oath that she would stand by the Curé
and fulfil the wishes of a dying and much-wronged woman.
Much perturbed, Monsieur le Curé went away. Lady Molly went
several times after that to the château of Porhoët to see the invalid,
who had taken a violent fancy to her. In October we had, perforce, to
return to England and to work, and the following spring we had news
from the Curé that Mademoiselle de Genneville was dead.
3

Lady Molly had certainly been working too hard, and was in a
feeble state of health when we reached Porhoët the following 19th of
September, less than twenty-four hours before the eventful moment
when the old clock would reveal the will and testament of
Mademoiselle de Genneville.
We walked straight from the station to the presbytery, anxious to
see the Curé and to make all arrangements for to-morrow’s
business. To our terrible sorrow and distress, we were informed by
the housekeeper that the Curé was very seriously ill at the hospital at
Brest, whither he had been removed by the doctor’s orders.
This was the first inkling I had that things would not go as
smoothly as I had anticipated. Miss de Genneville’s dispositions with
regard to the sensational disclosure of her will had, to my mind, been
so ably taken that it had never struck me until now that the Marquise
de Terhoven and her precious son would make a desperate fight
before they gave up all thoughts of the coveted fortune.
I imagined the Marquis hemmed in on every side; any violence
offered against the Curé or Lady Molly when they entered the
château in order to accomplish the task allotted to them being visited
by the sending of the confession to Monsieur le Procureur de la
République, when prosecution for forgery would immediately follow.
Damage to the clock itself would be punished in the same way.
But I had never thought of sudden illnesses, of—heaven help us!
—poison or unaccountable accidents to either the Curé or to the
woman I loved best in all the world.
No wonder Lady Molly looked pale and fragile as, having thanked
the housekeeper, we found our way back in silence to the convent
where we had once again engaged rooms.
Somehow the hospitality shown us last year had lost something of
its cordiality. Moreover, our bedrooms this time did not communicate
with one another, but opened out independently on to a stone
passage.
The sister who showed us upstairs explained, somewhat
shamefacedly, that as the Mother Superior had not expected us, she
had let the room which was between our two bedrooms to a lady
visitor, who, however, was ill in bed at the present moment.
That sixth sense, of which so much has been said and written, but
which I will not attempt to explain, told me plainly enough that we
were no longer amidst friends in the convent.
Had bribery been at work? Was the lady visitor a spy set upon our
movements by the Terhovens? It was impossible to say. I could no
longer chase away the many gloomy forebodings which assailed me
the rest of that day and drove away sleep during the night. I can
assure you that in my heart I wished all eccentric old ladies and their
hidden wills at the bottom of the sea.
My dear lady was apparently also very deeply perturbed; any
attempt on my part to broach the subject of Miss de Genneville’s will
was promptly and authoritatively checked by her. At the same time I
knew her well enough to guess that all these nameless dangers
which seemed to have crept up round her only served to enhance
her determination to carry out her old friend’s dying wishes to the
letter.
We went to bed quite early; for the first time without that delightful
final gossip, when events, plans, surmises and work were freely
discussed between us. The unseen lady visitor in the room which
separated us acted as a wet blanket on our intimacy.
I stayed with Lady Molly until she was in bed. She hardly talked to
me whilst she undressed, but when I kissed her “good-night” she
whispered almost inaudibly right into my ear:
“The Terhoven faction are at work. They may waylay you and offer
you a bribe to keep me out of the château to-morrow. Pretend to fall
in with their views. Accept all bribes and place yourself at their
disposal. I must not say more now. We are being spied upon.”
That my lady was, as usual, right in her surmises was proved
within the next five minutes. I had slipped out of her room, and was
just going into mine, when I heard my name spoken hardly above a
whisper, whilst I felt my arm gently seized from behind.
An elderly, somewhat florid, woman stood before me attired in a
dingy-coloured dressing-gown. She was pointing towards my own
bedroom door, implying her desire to accompany me to my room.
Remembering my dear lady’s parting injunctions, I nodded in
acquiescence. She followed me, after having peered cautiously up
and down the passage.
Then, when the door was duly closed, and she was satisfied that
we were alone, she said very abruptly:
“Miss Granard, tell me! you are poor, eh?—a paid companion to
your rich friend, what?”
Still thinking of Lady Molly’s commands, I replied with a pathetic
sigh.
“Then,” said the old lady, eagerly, “would you like to earn fifty
thousand francs?”
The eagerness with which I responded “Rather!” apparently
pleased her, for she gave a sigh of satisfaction.
“You know the story of my sister’s will—of the clock?” she asked
eagerly: “of your friend’s rôle in this shameless business?”
Once more I nodded. I knew that my lady had guessed rightly.
This was the Marquise de Terhoven, planted here in the convent to
gain my confidence, to spy on Lady Molly, and to offer me a bribe.
Now for some clever tactics on my part.
“Can you prevent your friend from being at the château to-morrow
before one o’clock?” asked the Marquise.
“Easily,” I replied calmly.
“How?”
“She is ill, as you know. The doctor has ordered her a sleeping
draught. I administer it. I can arrange that she has a strong dose in
the morning instead of her other medicine. She will sleep till the late
afternoon.”
I rattled this off glibly in my best French. Madame la Marquise
heaved a deep sigh of relief.
“Ah! that is good!” she said. “Then listen to me. Do as I tell you,
and to-morrow you will be richer by fifty thousand francs. Come to
the château in the morning, dressed in your friend’s clothes. My son
will be there; together you will assist at the opening of the secret
doors, and when my son has wound up the old clock himself, he will
place fifty thousand francs in your hands.”
“But Monsieur le Curé?” I suggested tentatively.
“He is ill,” she replied curtly.
But as she spoke these three words there was such an evil sneer
in her face, such a look of cruel triumph in her eyes, that all my worst
suspicions were at once confirmed.
Had these people’s unscrupulous rapacity indeed bribed some
needy country practitioner to put the Curé temporarily out of the
way? It was too awful to think of, and I can tell you that I needed all
my presence of mind, all my desire to act my part bravely and
intelligently to the end, not to fly from this woman in horror.
She gave me a few more instructions with regard to the services
which she and her precious son would expect of me on the morrow.
It seems that, some time before her death, Miss de Genneville had
laid strict injunctions on two of her most trusted men-servants to
remain in the château, and to be on the watch on the eventful 20th
day of September of this year, lest any serious violence be done to
the English lady or to the Curé. It was with a view to allay any
suspicion which might arise in the minds of these two men that the
Marquis desired me to impersonate Lady Molly to-morrow, and to
enter with him—on seemingly friendly terms—the room where stood
the monumental clock.
For these services, together with those whereby Lady Molly was to
be sent into a drugged sleep whilst the theft of the will was being
carried through, I—Mary Granard—was to receive from Monsieur le
Marquis de Terhoven the sum of fifty thousand francs.
All these matters being settled to this wicked woman’s apparent
satisfaction, she presently took hold of both my hands, shook them
warmly, and called me her dearest friend; assured me of everlasting
gratitude, and finally, to my intense relief, slipped noiselessly out of
my room.
4

I surmised—I think correctly—that Madame la Marquise would


spend most of the night with her ear glued to the thin partition which
separated her room from that of Lady Molly; so I did not dare to go
and report myself and the momentous conversation which I had just
had, and vaguely wondered when I should have an opportunity of
talking matters over with my dear lady without feeling that a spy was
at my heels.
The next morning when I went into her room, to my boundless
amazement—and before I had time to utter a word—she moaned
audibly, as if in great pain, and said feebly, but very distinctly:
“Oh, Mary! I’m so glad you’ve come. I feel terribly ill. I haven’t had
a wink of sleep all night, and I am too weak to attempt to get up.”
Fortunately my perceptions had not been dulled by the excitement
of the past few hours, and I could see that she was not so ill as she
made out. Her eyes sought mine as I approached her bed, and her
lips alone framed the words which I believed I interpreted correctly.
“Do as they want. I stay in bed. Will explain later.”
Evidently she had reason to think that we were being closely
watched; but what I could not understand was, what did she expect
would happen if she herself were not present when the opening of
the clock door would disclose the will? Did she want me to snatch
the document: to bear the brunt of the Terhovens’ wrath and
disappointment? It was not like her to be afraid of fulfilling a duty,
however dangerous that fulfilment might prove; and it certainly was
not like her to break a promise given to a dying person.
But, of course, my business was to obey. Assuming that our
movements were being watched, I poured out a dose of medicine for
my dear lady, which she took and then fell back on her pillows as if
exhausted.
“I think I could sleep now, Mary,” she said; “but wake me later on; I
must be at the château by twelve o’clock, you know.”
As one of Lady Molly’s boxes was in my room, I had no difficulty in
arraying myself in some of her clothes. Thus equipped and closely
veiled, still ignorant of my lady’s plans, anxious, but determined to
obey like a soldier, blindly and unquestioningly, I made my way to the
château a little before noon.
An old butler opened the door in answer to my ring, and in the
inner hall sat the Marquise de Terhoven, whilst her son was walking
agitatedly up and down.
“Ah! here comes my lady,” said the Marquise, with easy
unconcern. “You have come, my lady,” she added, rising and taking
my hand, “to perform a duty which will rob my son of a fortune which
by right should have been his. We can put no hindrance in your way,
under penalty of an appalling disgrace which would then fall on my
son; moreover, my late sister has filled this house with guards and
spies. So, believe me, you need have no fear. You can perform your
duty undisturbed. Perhaps you will not object to my son keeping you
company. My precious sister had the door of her room removed
before her death and a curtain put in its stead,” she concluded with
what was intended to be the sneer of a disappointed fortune-hunter,
“so the least call from you will bring her spies to your assistance.”
Without a word the Marquis and I bowed to one another, then,
preceded by the old family butler, we went up the monumental
staircase to what I suppose had been the eccentric old lady’s room.
The butler drew the portière curtain aside and he remained in the
corridor whilst we went within. There stood the massive clock exactly
as my lady had often described it to me. It was ticking with slow and
deep-toned majesty.
Monsieur le Marquis pointed to an armchair for me. He was
obviously in a state of terrible nerve-tension. He could not sit still,
and his fingers were incessantly clasped and unclasped with a
curious, febrile movement, which betrayed his intense agitation.
I was about to make a remark when he abruptly seized my wrist,
placed one finger to his lips, and pointed in the direction of the
portière. Apparently he thought that someone was on the watch
outside, but the clock itself was so placed that it could not be seen
by anyone who was not actually in the room.
After that we were both silent, whilst that old piece of mechanism
ticked on relentlessly, still hiding the secret which it contained.
I would have given two years’ salary to know what Lady Molly
would have wished me to do. Frankly, I fully expected to see her
walk in at any moment. I could not bring myself to believe that she
meant to shirk her duty.
But she had said to me, “Fall in with their views,” so that when,
presently, the Marquis beckoned to me across the room to come and
examine the clock, I obeyed readily enough. I felt, by that time, as if
my entire body was stuffed with needles and pins, which were
pricking my nerves and skin until I could have yelled with the agony
of the sensation.
I walked across the room as if in a dream, and looked at the
curious clock which, in less than fifteen minutes, would reveal its
hidden secret. I suppose cleverer people than poor Mary Granard
could enter into long philosophical disquisitions as to this dumb piece
of mechanism which held the fate of this ruined, unscrupulous
gambler safely within its doors; but I was only conscious of that
incessant tick, tick, tick, whilst my eyes literally ached with staring at
the door.
I don’t know now how it all happened, for, of course, I was taken
unawares; but the next moment I found myself quite helpless, hardly
able to breathe, for a woollen scarf was being wound round my
mouth, whilst two strong arms encircled my body so that I could not
move.
“This is only a protection for myself, my dear Miss Granard,” a
trembling voice whispered in my ear; “keep quite still; no harm will
come to you. In ten minutes you shall have your fifty thousand francs
in your pocket, and can walk unconcernedly out of the château.
Neither your English lady nor Monsieur le Curé can say that they
suffered any violence, nor will the clock be damaged. What happens
after that I care not. The law cannot wrest the old fool’s fortune from
me, once I have destroyed her accursed will.”
To begin to tell you what passed in my mind then were an
impossibility. Did I actually guess what would happen, and what my
dear lady had planned? Or was it merely the ingrafted sympathy
which exists between her and me which caused me to act blindly in
accordance with her wishes?
“Fall in with their views. Take their bribes,” she had said, and I—
like a soldier—obeyed this command to the letter.
I remained absolutely still, scarcely moving an eyelid as I watched
the face of the clock, the minutes speeding on—now three—now five
—now ten——
I could hear the Marquis’ stertorous breathing close beside me.
Was I dreaming, or did I really see now a dark line—the width of a
hair—between the massive double doors of the clock case? Oh, how
my pulses throbbed!
That dark line was widening perceptibly. The doors were slowly
opening! For the moment I almost felt in sympathy with the
blackguard who was on the watch with me. His agitation must have
been the most exquisite torture.
Now we could distinctly see the glimmer of white paper—not
pressed down by the ponderous weights, but lying loosely just inside
the doors; and anon, as the aperture widened, the papers fell out just
at my feet.
With a smothered, gurgling exclamation which I will not attempt to
describe, the Marquis literally fell on that paper, like a hungry wild
beast upon its prey. He was on his knees before me, and I could see
that the paper was a square envelope, which, with a trembling hand,
he tore open.
It contained a short document whereon the signature “Amédé de
Terhoven” was clearly visible. It was the confession of forgery made
by the young Marquis just a year ago; there were also a few bank-
notes: some hundred thousand francs, perhaps. The young man
threw them furiously aside, and once more turned to the clock. The
doors were wide open, but they revealed nothing save the huge and
complicated mechanism of the clock.
Mademoiselle de Genneville—eccentric and far-seeing
“Now we could distinctly see the glimmer of white paper”

to the last—had played this gigantic hoax on her scheming relatives.


Whilst they directed all their unscrupulous energies towards trying to
obtain possession of her will in one place, she had calmly put it
securely somewhere else.
Meantime, Monsieur le Marquis had sufficient presence of mind,
and, I must own, sufficient dignity, not only to release me from my
bonds but also to offer me the fifty thousand francs which he had
promised me.
“I can wind up the clock now,” he said dully, “and you can walk
straight out of this place. No one need know that you impersonated
your friend. She, no doubt, knew of this—hoax; therefore we found
the scheme to keep her out of the way so easy of accomplishment. It
was a grisly joke, wasn’t it? How the old witch must be chortling in
her grave!”
Needless to say, I did not take his money. He escorted me
downstairs silently, subdued, no doubt, by the spirit of hatred which
had followed him up from the land of shadows.
He even showed no surprise when, on reaching the hall, he was
met by his late aunt’s lawyer, Maître Vendôme, and also by Lady
Molly, who had just arrived. Madame la Marquise de Terhoven was
nowhere to be seen.
My dear lady smiled at me approvingly, and when I came near her
she contrived to draw me aside and to whisper hurriedly:
“You have done admirably, Mary. I came to fetch you. But now that
this young blackguard is thoroughly outwitted, we may as well go, for
our work here is done.”
The Marquis did not even glance at her as she slightly bowed her
head to him, took leave of Maître Vendôme, and finally walked out of
the château with me.
As soon as we were out in the open air I begged for an
explanation.
“Maître Vendôme has Mademoiselle’s will,” she replied. “She had
enjoined him to read it in the château to-day in the presence of the
three trustees appointed for the poor of Porhoët, who inherit all her
wealth.”
“And the Terhovens?” I asked.
“They’ve got his confession back,” she said dryly, “and they will
receive an annuity from the trustees.”
“And you knew this all along?” I rejoined somewhat reproachfully.
“Yes, so did the Curé, but Mademoiselle made me swear a most
solemn oath not to reveal her secret even to you; she was so afraid
of the machinations of the Terhovens. You see,” continued Lady
Molly, smiling at my eagerness, “Miss de Genneville possessed the
ancient key wherewith she could open the clock case at any time.
Obviously, even so perfect a piece of mechanism might go wrong,
when examination and re-adjustment of the works would be
necessary. After the family conclave wherein she had announced
that her will was hidden in the clock, I—at my next interview with her
—begged her to modify this idea, to send her will to her solicitor, but
to leave the Terhovens under the impression that it was still lying in
its strange hiding place. At first she refused to listen to me or to
discuss the subject, but I am happy to say that I finally succeeded in
persuading her, with what result you already know.”
“But poor Monsieur le Curé!” I ejaculated.
Her bright eyes gleamed with merriment.
“Oh! that was a final little hoax. He himself, poor dear, was afraid
lest he might blurt out the whole thing. His illness was partly a sham,
and he is quite all right again now, but the doctor at the Brest
hospital is a great friend of his, and is keeping him there until all this
business has blown over.”
“I was the only one who was kept in the dark,” I concluded ruefully.
“Yes, Mary, dear,” said my dear lady, gently; “it was a promise,
remember. But I never thought that we should get so much
excitement outside our own professional work.”
It certainly had been a non-professional experience; but here, too,
as in the detection of crime, her keen intuition had proved more than
a match for an unscrupulous blackguard, and certainly on the 20th
day of September last I lived through the most exciting ten minutes
of my life.
VII.
A CHRISTMAS TRAGEDY

It was a fairly merry Christmas party, although the surliness of our


host somewhat marred the festivities. But imagine two such beautiful
young women as my own dear lady and Margaret Ceely, and a
Christmas Eve Cinderella in the beautiful ball-room at Clevere Hall,
and you will understand that even Major Ceely’s well-known
cantankerous temper could not altogether spoil the merriment of a
good, old-fashioned, festive gathering.
It is a far cry from a Christmas Eve party to a series of cattle-
maiming outrages, yet I am forced to mention these now, for
although they were ultimately proved to have no connection with the
murder of the unfortunate Major, yet they were undoubtedly the
means whereby the miscreant was enabled to accomplish the
horrible deed with surety, swiftness, and—as it turned out afterwards
—a very grave chance of immunity.
Everyone in the neighbourhood had been taking the keenest
possible interest in those dastardly outrages against innocent
animals. They were either the work of desperate ruffians who stick at
nothing in order to obtain a few shillings, or else of madmen with
weird propensities for purposeless crimes.
Once or twice suspicious characters had been seen lurking about
in the fields, and on more than one occasion a cart was heard in the
middle of the night driving away at furious speed. Whenever this
occurred the discovery of a fresh outrage was sure to follow, but, so
far, the miscreants had succeeded in baffling not only the police, but
also the many farm hands who had formed themselves into a band
of volunteer watchmen, determined to bring the cattle maimers to
justice.
We had all been talking about these mysterious events during the
dinner which preceded the dance at Clevere Hall; but later on, when
the young people had assembled, and when the first strains of “The
Merry Widow” waltz had set us aglow with prospective enjoyment,
the unpleasant topic was wholly forgotten.
The guests went away early, Major Ceely, as usual, doing nothing
to detain them; and by midnight all of us who were staying in the
house had gone up to bed.
My dear lady and I shared a bedroom and dressing-room together,
our windows giving on the front. Clevere Hall is, as you know, not
very far from York, on the other side of Bishopthorpe, and is one of
the finest old mansions in the neighbourhood, its only disadvantage
being that, in spite of the gardens being very extensive in the rear,
the front of the house lies very near the road.
It was about two hours after I had switched off the electric light and
called out “Good-night” to my dear lady, that something roused me
out of my first sleep. Suddenly I felt very wide-awake, and sat up in
bed. Most unmistakably—though still from some considerable
distance along the road—came the sound of a cart being driven at
unusual speed.
Evidently my dear lady was also awake. She jumped out of bed
and, drawing aside the curtains, looked out of the window. The same
idea had, of course, flashed upon us both, at the very moment of
waking: all the conversations anent the cattle-maimers and their cart,
which we had heard since our arrival at Clevere, recurring to our
minds simultaneously.
I had joined Lady Molly beside the window, and I don’t know how
many minutes we remained there in observation, not more than two
probably, for anon the sound of the cart died away in the distance
along a side road. Suddenly we were startled with a terrible cry of
“Murder! Help! Help!” issuing from the other side of the house,
followed by an awful, deadly silence. I stood there near the window
shivering with terror, while my dear lady, having already turned on
the light, was hastily slipping into some clothes.
The cry had, of course, aroused the entire household, but my dear
lady was even then the first to get downstairs, and to reach the
garden door at the back of the house, whence the weird and
despairing cry had undoubtedly proceeded.
That door was wide open. Two steps lead from it to the terraced
walk which borders the house on that side, and along these steps
Major Ceely was lying, face downwards, with arms outstretched, and
a terrible wound between his shoulder-blades.
A gun was lying close by—his own. It was easy to conjecture that
he, too, hearing the rumble of the wheels, had run out, gun in hand,
meaning, no doubt, to effect, or at least to help, in the capture of the
escaping criminals. Someone had been lying in wait for him; that
was obvious—someone who had perhaps waited and watched for
this special opportunity for days, or even weeks, in order to catch the
unfortunate man unawares.
Well, it were useless to recapitulate all the various little incidents
which occurred from the moment when Lady Molly and the butler
first lifted the Major’s lifeless body from the terrace steps until that
instant when Miss Ceely, with remarkable coolness and presence of
mind, gave what details she could of the terrible event to the local
police inspector and to the doctor, both hastily summoned.
These little incidents, with but slight variations, occur in every
instance when a crime has been committed. The broad facts alone
are of weird and paramount interest.
Major Ceely was dead. He had been stabbed with amazing
sureness and terrible violence in the back. The weapon used must
have been some sort of heavy, clasp knife. The murdered man was
now lying in his own bedroom upstairs, even as the Christmas bells
on that cold, crisp morning sent cheering echoes through the
stillness of the air.
We had, of course, left the house, as had all the other guests.
Everyone felt the deepest possible sympathy for the beautiful young
girl who had been so full of the joy of living but a few hours ago, and
was now the pivot round which revolved the weird shadow of
tragedy, of curious suspicions and of an ever-growing mystery. But at
such times all strangers, acquaintances, and even friends in a
house, are only an additional burden to an already overwhelming
load of sorrow and of trouble.
We took up our quarters at the “Black Swan,” in York. The local
superintendent, hearing that Lady Molly had been actually a guest at
Clevere on the night of the murder, had asked her to remain in the
neighbourhood.
There was no doubt that she could easily obtain the chief’s
consent to assist the local police in the elucidation of this
extraordinary crime. At this time both her reputation and her
remarkable powers were at their zenith, and there was not a single
member of the entire police force in the kingdom who would not have
availed himself gladly of her help when confronted with a seemingly
impenetrable mystery.
That the murder of Major Ceely threatened to become such no
one could deny. In cases of this sort, when no robbery of any kind
has accompanied the graver crime, it is the duty of the police and
also of the coroner to try to find out, first and foremost, what possible
motive there could be behind so cowardly an assault; and among
motives, of course, deadly hatred, revenge, and animosity stand
paramount.
But here the police were at once confronted with the terrible
difficulty, not of discovering whether Major Ceely had an enemy at
all, but rather which, of all those people who owed him a grudge,
hated him sufficiently to risk hanging for the sake of getting him out
of the way.
As a matter of fact, the unfortunate Major was one of those
miserable people who seem to live in a state of perpetual enmity with
everything and everybody. Morning, noon and night he grumbled,
and when he did not grumble he quarrelled either with his own
daughter or with the people of his household, or with his neighbours.
I had often heard about him and his eccentric, disagreeable ways
from Lady Molly, who had known him for many years. She—like
everybody in the county who otherwise would have shunned the old
man—kept up a semblance of friendship with him for the sake of the
daughter.
Margaret Ceely was a singularly beautiful girl, and as the Major
was reputed to be very wealthy, these two facts perhaps combined
to prevent the irascible gentleman from living in quite so complete an
isolation as he would have wished.
Mammas of marriageable young men vied with one another in
their welcome to Miss Ceely at garden parties, dances and bazaars.
Indeed, Margaret had been surrounded with admirers ever since she
had come out of the schoolroom. Needless to say, the cantankerous

You might also like