PDF Programming in C 1st Edition - Ebook PDF Download
PDF Programming in C 1st Edition - Ebook PDF Download
com
https://ebooksecure.com/download/programming-in-c-
ebook-pdf/
https://ebooksecure.com/download/programming-in-ansi-c-ebook-pdf/
ebooksecure.com
https://ebooksecure.com/download/readings-from-programming-with-c-
ebook-pdf-2/
ebooksecure.com
https://ebooksecure.com/download/readings-from-programming-with-c-
ebook-pdf/
ebooksecure.com
https://ebooksecure.com/product/ebook-pdf-data-mining-and-predictive-
analytics-2nd-edition/
ebooksecure.com
https://ebooksecure.com/product/introduction-to-probability-and-
statistics-14th-edition-ebook-pdf/
ebooksecure.com
https://ebooksecure.com/download/understanding-basic-statistics-ebook-
pdf-2/
ebooksecure.com
https://ebooksecure.com/product/human-development-a-life-span-
view-7th-edition-ebook-pdf/
ebooksecure.com
https://ebooksecure.com/download/winning-the-brain-game-fixing-
the-7-fatal-flaws-of-thinking-ebook-pdf/
ebooksecure.com
(eBook PDF) Inorganic Chemistry 7th Edition by Mark Weller
https://ebooksecure.com/product/ebook-pdf-inorganic-chemistry-7th-
edition-by-mark-weller/
ebooksecure.com
Programming in C
About the Author
E Balagurusamy, is presently the Chairman of EBG Foundation, Coimbatore. In the past he has also
held the positions of member, Union Public Service Commission, New Delhi and Vice-Chancellor, Anna
University, Chennai. He is a teacher, trainer and consultant in the fields of Information Technology
and Management. He holds an ME (Hons) in Electrical Engineering and PhD in Systems Engineering
from the Indian Institute of Technology, Roorkee. His areas of interest include Object-Oriented Software
Engineering, E-Governance: Technology Management, Business Process Re-engineering and Total
Quality Management.
A prolific writer, he has authored a large number of research papers and several books. His best-selling
books, among others include:
∑ Fundamentals of Computers
∑ Computing Fundamentals and C Programming, 2e
∑ Programming in C#, 3/e
∑ Programming in Java, 5/e
∑ Object-Oriented Programming with C++, 7/e
∑ Numerical Methods
∑ Reliability Engineering
A recipient of numerous honors and awards, he has been listed in the Directory of Who's Who of
Intellectuals and in the Directory of Distinguished Leaders in Education.
Programming in C
E Balagurusamy
Chairman
EBG Foundation
Coimbatore
Programming in C
Copyright © 2018, by McGraw Hill Education (India) Private Limited. No part of this publication may be repro-
duced or distributed in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise
or stored in a database or retrieval system without the prior written permission of the publishers. The program
listings (if any) may be entered, stored and executed in a computer system, but they may not be reproduced for
publication.
ISBN-13: 978-93-87432-36-9
ISBN-10: 93-87432-36-X
1 23456789 D101417 22 21 20 19 18
Printed and bound in India.
Managing Director: Kaushik Bellani
Director—Science & Engineering Portfolio: Vibha Mahajan
Senior Portfolio Manager—Science & Engineering: Hemant K Jha
Associate Portfolio Manager—Science & Engineering: Mohammad Salman Khurshid
Production Head: Satinder S Baveja
Assistant Manager—Production: Anuj K Shriwastava
General Manager—Production: Rajender P Ghansela
Manager—Production: Reji Kumar
Information contained in this work has been obtained by McGraw Hill Education (India), from sources believed
to be reliable. However, neither McGraw Hill Education (India) nor its authors guarantee the accuracy or
completeness of any information published herein, and neither McGraw Hill Education (India) nor its authors
shall be responsible for any errors, omissions, or damages arising out of use of this information. This work is
published with the understanding that McGraw Hill Education (India) and its authors are supplying information
but are not attempting to render engineering or other professional services. If such services are required, the
assistance of an appropriate professional should be sought.
Typeset at The Composers, 260, C.A. Apt., Paschim Vihar, New Delhi 110 063 and printed at
Preface xiii
Constants 27
Variables 31
Data Types 32
Declaration of Variables 35
Declaration of Storage Class 38
Assigning Values to Variables 39
Defining Symbolic Constants 44
Declaring a Variable as Constant 46
Declaring a Variable as Volatile 46
Key Concepts 46
Always Remember 47
Brief Cases 47
Review Questions 50
Debugging Exercises 51
Programming Exercises 52
UNIT 4: sTrUcTUrEs
12. Structures and Unions 381
Introduction 381
Defining a Structure 382
Declaring Structure Variables 383
Accessing Structure Members 385
Visit https://testbankfan.com
now to explore a rich
collection of testbank or
solution manual and enjoy
exciting offers!
Contents xi
Annexure 1: Model Question Papers with Hints and Short Solutions 473
annexure 2: Developing a c Program: some guidelines 492
Appendix I: Bit-Level Programming 507
appendix II: ascII Values of characters 512
Appendix III: ANSI C Library Functions 514
Preface
C
is a powerful, flexible, portable and elegantly structured programming language. Since C
combines the features of high-level language with the elements of the assembler, it is suitable
for both systems and applications programming. It is undoubtedly the most widely used general-
purpose language today in operating systems, and embedded system development. Its influence
is evident in almost all modern programming languages. Since its standardization in 1989, C has
undergone a series of changes and improvements in order to enhance the usefulness of the language.
The version that incorporates the new features is now referred to as C11.
Digital supplements
The digital supplement can be accessed at the given link (http://www.mhhe.com/balagurusamy/picau17)
It contains the following components:
∑ Write up on Self Referential Structures
∑ Write up on Selection sort, linear and binary search
∑ Additional Programs for practice
xiv Preface
feedback
I welcome any constructive criticism of the book and will be grateful for any appraisal by the readers.
Feedback to improve the book will be highly appreciated.
E Balagurusamy
Publisher’s Note
McGraw Hill Education (India) invites suggestions and comments from you, all of which can be sent
to info.india@mheducation.com (kindly mention the title and author name in the subject line). Piracy-
related issues may also be reported.
UNIT 1
Basics of C Programming
Chapter 1 Overview of C
Chapter 2 Constants, Variables and Data Types
Chapter 3 Operators and Expressions
Chapter 4 Managing Input and Output Operations
Chapter 5 Decision Making and Branching
Chapter 6 Decision Making and Looping
Chapter 7 The Preprocessor
Exploring the Variety of Random
Documents with Different Content
annum. This estimate includes the cost of the male staff. The
proportionate rate of expenditure in respect of the lady workers of
the English Mission is one-third of this annual disbursement less. The
depôts of the Mission are situated at Seoul, Chemulpo, Mok-po, and
Kang-wha; in addition to the stations in Korea, a chaplaincy is
maintained in New-chwang. The chief centre of activity of this
Mission is upon the island of Kang-wha. The task of improving the
condition of the very poor, by means of education, kindness and
patience, proceeds quietly at Chemulpo and Seoul too, where
particular attention is given to the welfare of the sick. At one time,
there were important dispensary and hospital institutes in these
places, the medical establishment at Chemulpo, however, is now
abandoned.
The members of this Mission endure no little privation in the
primitive simplicity of their surroundings. Their services, on the other
hand, display much unnecessary pomp; and the white, full-skirted
cassock with rough hempen girdle, which they wear in public and
private, emphasises their ritualistic tendencies, and is, to my mind,
somewhat of an affectation. Nevertheless, in their daily practice,
those associated with the Church of England Mission in Korea set
before themselves that standard of idealism in missionary enterprise
which is represented by the unnecessary sacrifices, the sublime
heroism, and fortitude distinguishing the priests of the Roman
Catholic Church, a standard, I am compelled to admit, that other
missions in the Far East—American, English, Scotch, and Irish—
appear incapable of realising.
The American missionary in the Far East is a curious creature. He
represents a union of devices which have made him a factor of
considerable commercial importance. American missionaries in Korea
were formerly closely associated with the more important export
houses in the leading industrial centres of America. Owing to
diplomatic representation this practical demonstration of Western
superiority is no longer openly indulged. In Seoul, however, an
American missionary inconsiderately receives paying guests, causing
a manifest loss of business to the Station Hotel; in Won-san, another
exploits his orchard. As a class they are necessarily newspaper
correspondents and professional photographers; upon rare occasions
—and here I refer especially to a small coterie of American
missionaries in Seoul—they are the scholarly students of the history,
manners, customs and language of the country in which they
happen to be placed.
The American missionary has a salary which frequently exceeds
£200 a year, and is invariably pleasantly supplemented by additional
allowances. Houses and servants are provided free, or grants are
made for house rent; there is a provision for the education of the
children, and an annual capitation payment is made for each child.
As a class, American missionaries have large families, who live in
comparative idleness and luxury. In Korea, they own the most
attractive and commodious houses in the foreign settlements, and
appear to me to extract from their surroundings the maximum of
profit for the minimum of labour. I do not know whether it is with
the permission of the executive officers of the American Mission
Boards that their representatives combine commerce with their
mission to the heathen. When a missionary devotes no little portion
of his time to literary labours, to the care of an insurance agency, to
the needs of a fruit farm, or to the manifold exigencies of casual
commerce, it seems to me that the interests of those who sit in
darkness must suffer.
American mission agents have made Korea their peculiar field.
Converts, who prattle of Christianity in a marked American accent,
are among the features of the capital in the twentieth century.
Mission centres, which have been created in a number of places,
now show signs of prosperity. They enlist no little practical sympathy
and support from the native population. The self-supporting
character of much of the missionary work in Korea bears out the
spirit of toleration which distinguishes the attitude of the people
towards the propaganda. It is not to be supposed that the work of
the missionaries is agreeable to all shades of native opinion. Riots
and bloodshed disfigure the path of proselytism, the credulity of the
natives entailing heavy sacrifices of life. The disturbances which
have thus marked the spread of Christianity in Korea, notably in the
anti-Christian rising in Quelpart, a few months ago, are due to the
jealousy with which the heathen mass of the population regard the
protection from official rapacity, enjoyed by those who accept The
Light.
In the case of Quelpart, this feeling of animosity, and the
immunity from taxation which the French priests gave to their
following, created an intolerable position. Anarchy swept over the
island, and some six hundred believers were put summarily to death.
Whatever may be the compensating advantages of this martyrdom,
the reckless and profligate sacrifice of life, which missionary
indiscretion in the Far East has promoted, is an outrage upon
modern civilisation. We have passed through one terrible anti-
Christian upheaval in China, and, if we wish to avoid another such
manifestation, it is necessary to superintend all forms of missionary
enterprise more closely. This, however, can be done only by
legislative supervision, imposing restraint in the direction which
recent events have indicated. It is imperative that certain measures
should be adopted in missionary work which will ensure the safety of
the individual zealot, and be agreeable to the general comfort of the
community. It is unfortunate, but inevitable, that such reforms must
be radical. The violence of missionary enterprise during recent years
has been altogether unbridled. The great activity of the different
societies, resulting from their unrestricted liberty, has recoiled most
fatally upon the more indefatigable, as well as upon the heads of
many wholly innocent of any unwarrantable religious persecution.
The time has come, therefore, when vigorous restrictions should
chasten this vigorous, polemical proselytism. The practice of
scattering missionaries broadcast over the interior of these Far
Eastern countries should not continue; the assent of the local Consul
and a representative council of the Foreign Ministers should be
required in every case. Moreover, it would be wiser, if, under no
conceivable circumstances, single women were permitted to
proselytise beyond the carefully prescribed treaty limits of the
different settlements. Again, missionaries with families, as well as
single women, should not be allowed to live beyond the areas of
these neutral zones.
The salt water estuary of the Han is tempestuous and deep, given
over to much shipping and small craft. The river itself does not begin
for twenty miles above the tide-water mouth, the intervening stretch
of water belonging more correctly to the sea. Above Chemulpo,
where the full force of the Han current is hardly felt, the velocity of
the stream is quite five knots an hour. Where the breadth of the river
narrows the rapidity of the flow increases. At a point, where the river
makes a sudden sweep round some overhanging bluffs, which
confront each other from opposite banks, the heavy volume of water
thus tumbling down becomes a swirling, boisterous mill-race, as it
twists and foams through its tortuous channels into another tide-
swollen reach. The place of meeting between the sea and the river
current shows itself in a line of choppy water, neither rough nor
smooth. The water is always bubbling and always breaking at this
point, in a manner poetically suggestive of the spirits of the restless
deep. The Han river gives access to Seoul. In the days before the
railway, the choice of route to the capital lay between spending a
night aground upon one of the many shifting sand-banks in the river
or the risks of a belated journey overland, with pack ponies and the
delights of a sand-bath in the Little Sahara. There were many who
found the “all land” way preferable to the “land and water system,”
to which many groundings and much wading reduced the
experiment of travelling by junk or steam-launch in those days. Now,
however, the iron horse rules the road.
My little holiday passed all too quickly. One day I found myself
preparing very sorrowfully to return to Seoul. This accomplished, the
news of my intended journey was quickly bruited abroad by my
servants. During these days curio-dealers crowded the compound of
the Station Hotel, where, made very comfortable by the kindly
forethought of Mr. and Mrs. Emberley, I was still living. There is little
enough to buy in Seoul: quaint, brass cooking-utensils; iron, inlaid
with silver; tobacco boxes, jade cups, fans, screens, and scrolls. My
purchases were few; the native furniture, massive presses, and
cabinets faced with copper plates, and small tea-tables, attracting
me more than anything else. The Emperor had already sent a
present of silk and fans to my hotel, and, with these few remaining
articles, my stock of Korean relics was completed. The dealers were
importunate, and crowded into the private apartments of the hotel
like bleating sheep into a pen. Remonstrances were in vain, and I
found the specific cure for their pestiferous attentions to be
administered best in the shape of a little vigorous kicking. They took
the cuffing with much good humour, and retired to the courtyard,
where, at intervals in the day, a plaintive voice would be heard
calling upon His Highness to inspect the treasures of his slave. His
Highness, however, had concluded his inspection.
The atmosphere in these hot days in Seoul was very bad; the air
was heavy with malodorous vapour; the days were muggy and the
nights damp. The steaming heat of the capital emphasised the
wisdom of an immediate departure, and I hastened my exodus,
touched up with a little ague and a troublesome throat. The endless
business of obtaining servants, guides, and horses was repeated,
until at last the day of my removal was arranged and the hour of
actual departure fixed. The prospect was alluring—a journey from
Seoul to Vladivostock, through a wild and desolate region, nearly
eight hundred miles in length, lay before me. Much of it was
unexplored. It was the chance of a lifetime, and, in thus embarking
upon it, I was very happy. My last farewells were said; my last calls
had been paid—the kindly hospitality of Seoul is not forgotten. The
day had come at last, the horses were pawing in the courtyard. My
effects, my guns, and camp-bed, my tent and stores, were packed
and roped. The horses had been loaded; the hotel account had been
settled, when my interpreter quietly told me that my servants had
struck for ten dollars Mexican—one sovereign—monthly increase in
the wages of each. Mr. Emberley stood out against the transaction; I
offered to compound with half; they were obdurate. It seemed to
me that a crisis was impending. I was too tired and too cross to
remonstrate. I raised my offer to eight dollars; it was refused—the
servants were dismissed. Uproar broke out in the courtyard, which
Mr. Emberley pacified by inducing the boys to accept my last offer—a
rise of eight dollars Mexican. My head-servant, the brother of my
interpreter, repudiated the arrangement, but the significance of this
increase had assumed great importance. It was necessary to be
firm. I think now that it was unwise to have entertained any change
at all in the standard of payment. Upon the question of the
additional two dollars I stood firm; nothing more would be given.
The interpreter approached me to intimate that if his brother did not
go he also would stay behind. I looked at him for a moment, at last
understanding the plot, and struck him. He ran into the courtyard
and yelled that he was dead—that he had been murdered. The
grooms in charge of the horses gathered round him with loud cries
of sympathy. Mr. Emberley called them to him and explained the
position of affairs. I strode into the compound. The head groom
came up to me, demanding an increase of thirty dollars, Korean
currency, upon the terms which he had already accepted; he
wanted, further, three-quarters of the contract price to be paid in
advance; one quarter was the original stipulation. I refused the thirty
dollars, and thrashed him with my whip.
The end of my journey for the moment had come, with a
vengeance. The head groom stormed and cursed and ran raving in
and out of the crowd. He then came for me with a huge boulder,
and, as I let out upon his temple, the riot began. My baggage was
thrown off the horses and stones flew through the air. I hit and
slashed at my assailants and for a few minutes became the centre of
a very nasty situation. Servants and grooms, my interpreter, and a
few of the spectators went at it keenly while the fight continued. In
the end, Mr. Emberley cleared his courtyard and recovered my kit;
but I was cut a little upon the head and my right hand showed a
compound fracture—native heads are bad things to hammer.
Postponement was now more than ever essential; my fears about
my health were realised. By nightfall upon the day of this outbreak
signs of sickness had developed; the pain had increased in my hand
and arm; my head was aching; my throat was inflamed. I was
advised to leave at once for Japan; upon the next day I sailed,
proposing to go to Yokohama and thence to Vladivostock, starting
the expedition from the Russian fortress. However, by the time my
steamer arrived at Japan, I was in the clutch of enteric fever. Further
travel was out of the question, and when they moved me from an
hotel in Yokohama to a cabin upon a Japanese steamer, which was
to carry me to England, in my mind I had bidden farewell to the
countries of this world, for the doctor told me that I was dying.
APPENDIX I
SCHEDULE OF TRAIN SERVICE