Home > Store

C for COBOL Programmers: A Business Approach

Register your product to gain access to bonus material or receive a coupon.

C for COBOL Programmers: A Business Approach

Book

  • Sorry, this book is no longer in print.
Not for Sale

About

Features

Written by an experienced business data systems designer, this new tutorial provides an ideal introduction to C for the COBOL programmer who wants to become proficient in the powerful C language. Featuring side-by-side comparisons of the syntax and constructs of the two languages, C for COBOL Programmers uses the reader's knowledge of COBOL to build a framework for learning C quickly and easily. The book introduces coded examples in C early, and in the context of a business environment. A complete chapter is devoted to explaining the important differences between COBOL and C for data handling and I/O, while another chapter focusses on C programming standards as applied to business data processing. A valuable appendix cross-references COBOL commands to C commands, operators, and functions.

  • Over 60 side-by-side examples of COBOL code and C code.
  • Four-level approach, with increasing detail at each level:
    • Introduction to each topic
    • Basic syntax for each C keyword or function
    • Anatomy of syntax and discussion of uses and pitfalls
    • Common errors and example programs
  • Table of Contents which uses both COBOL and C terminology.
  • An introductory chapter on C++, the object-oriented programming language extension of C.
  • Practical indexing and cross-reference tools, including:
    • List of C functions, with syntax, on the inside front and back covers
    • Quick Guide to Chapters page for topics-at-a-glance
    • An appendix which contains a COBOL-to-C cross-reference guide
  • Over 40 tested example programs, each of which has comments within the code as well as more detailed comments following the program.
  • Example programs available free on-line or for a nominal charge on disk.
What Reviewers Are Saying
"Finally! A C book that makes the language and concepts understandable to the business application programmer."
--Joanna Manthos, IBM
Audience

Professional/Reference

Sophomore/Junior/Senior Computer Science majors

Courses:
Programming Languages
Data Structures
Object-Oriented Programming
Advanced Programming
C
Prerequisites:
COBOL Programming

Written by an experienced business data systems designer, this new tutorial provides an ideal introduction to C for the COBOL programmer who wants to become proficient in the powerful C language. Featuring side-by-side comparisons of the syntax and constructs of the two languages, C for COBOL Programmers uses the reader's knowledge of COBOL to build a framework for learning C quickly and easily. The book introduces coded examples in C early, and in the context of a business environment. A complete chapter is devoted to explaining the important differences between COBOL and C for data handling and I/O, while another chapter focusses on C programming standards as applied to business data processing. A valuable appendix cross-references COBOL commands to C commands, operators, and functions.

Description

  • Copyright 1996
  • Edition: 1st
  • Book
  • ISBN-10: 0-8053-1660-4
  • ISBN-13: 978-0-8053-1660-5

Written by an experienced business data systems designer and programmer, this new tutorial provides an ideal introduction to C for the COBOL programmer who wants to become proficient in the powerful C language. Featuring side-by-side comparisons of the syntax and constructs of the two languages, C for COBOL Programmers uses the reader's knowledge of COBOL to build a framework for learning C quickly and easily. The book introduces coded examples in C early, and in the context of a business environment. A complete chapter is devoted to explaining the important differences between COBOL and C for data handling and I/O, while another chapter focusses on C programming standards as applied to business data processing. A valuable appendix cross-references COBOL commands to C commands, operators, and functions.



0805316604B08022001

Downloads

Source Code

Click below for Source Code related to this title:
Program Code

Supplements

I believe that there are only a few people who ever read a computer language book from beginning to end: the author, the copy editor, and kind reviewers.

We programmers are generally impatient and want to get to the heart of the matter immediately. We usually read the first 20 or 30 pages of a computer language book and begin our work. Then we come back to the book for new topics, further explanation, or to figure out problems. The problem for the author is how to combine teaching and reference material in the same book.

With that in mind, I have designed this book to work on several different levels. These levels are:

  1. Give me an introduction.
  2. Give me the syntax.
  3. Give me the detail.
  4. What's wrong with my program?

Here's how they work:

1. Give me an introduction.

The first two chapters of the book are a general introduction to the C language. Chapter 1 compares and contrasts C with COBOL. Chapter 2 covers compiling, formatting, and comments. This is the only part of the book I expect you will read straight through.

In addition, each chapter begins with an introduction, in English, to the programming topic of that chapter.

2. Give me the syntax.

The next level of use occurs when you want to use or learn about a C keyword (reserved word) or function (subprogram) and want the basic syntax. This is addressed on the first page of each section about a C operator or function. The C language uses functions to do a lot of the work of the language. When you see the word function, think "subprogram."

The first page contains the syntax, a code sample, any include file (copy member) needed, a short description of the operator or function, how parameters must be defined, and what is contained in the return value (RETURN-CODE) of a function call. This is generally enough for people who need to refresh their memories or have been programming in C long enough to not need a detailed explanation.

3. Give me the detail.

When you want a more detailed explanation of the syntax and more discussion of the operator or function, you can continue to read the detailed examination of the parts of the statement (anatomy) and a general discussion. After each discussion there is a short section on common errors for the topic discussed.

You may also continue reading the next two parts, which are the example program and a set of comments about the example program.

The example program and comments are designed to work on two levels. Within the example program there are comments on the right side of the significant statements, which give a capsule description of the action taking place in the statement. This is followed by a comments section where there is more detail on each significant statement in the example program.

The example program typically contains several of the common errors made for that C operator or function. This is especially important for people coming from COBOL, because several underlying assumptions in the C language are different from or opposite to the corresponding assumptions in COBOL.

4. What's wrong with my program?

When a program does not work the way you think it should, you may want to review the syntax at the beginning of the section, review the parameter definitions, review the common errors, and then look at the example program and its comments to get clues about your problem.

This is why the detailed comments are often longer than the example program. These comments not only explain how things work, but why certain techniques should be used and why other techniques should not be used.

A Few Comments on Repetition

Those of you valiant enough to read this book cover-to-cover will find a lot of repetition in it. As the famous software saying goes, "That's not a defect, it's a feature!"

The repetition is here for two reasons. My observation is that most people read between three paragraphs and two pages when they look at a computer book. Repeating topics and tips increases the likelihood that important material will be found when "dipping." And for people who read whole chapters, the repetition reinforces the learning process.

Condensed List of Functions

Inside the front and back covers of this book is a list of all the functions and operators discussed in the book. After you acquire a degree of familiarity with C, you often only need the syntax for a given operator or function. Instead of having to search the index or table of contents to find the page, you can look inside the covers and find the basic syntax. The page number where the operator/function is discussed is also shown.

Quick Guide to Chapters

This book has been designed with a block on the outer edge of the first page of each chapter. The Quick Guide to Chapters page has all the chapters of the book listed, with blocks that match the ones in the chapters. This is another feature to help you find things quickly.

Table of Contents

I have written the Table of Contents using (mostly) English or COBOL terms, which is unusual for a book on C. You should be able to recognize almost every topic. This is the way natural language books are structured: syntax and grammar of the known language are used to teach the new language.

Additionally, C keywords and operators are shown to the right of page numbers where they are discussed. This is provided as another cross-reference.

Summary

I have written the book I wanted to find when I learned C. I use language books in several different ways, so I have tried to make this one useful in several different ways. If this book makes the C language seem understandable and accessible to you, then I have succeeded.

Jim Gearing

Sample Content

Table of Contents

(Eacha chapter begins with "Introduction" and concludes with "Summary".)

Quick Guide to Chapters.


Preface.


Acknowledgements.


How to Use This Book.


1. From COBOL to C.

Introduction.

Which C? Which COBOL? Which Computer?

Sample Programs: Free On-line or Cheap by Mail.

Evolution of C.

A Quick Survey of C Compared to COBOL.

Fundamental Concepts of COBOL and C Compared.

Program Organization in COBOL and C.

A Minimal COBOL Program (Two Versions).

A Minimal C Program.

How COBOL Translates to C.

Summary.



2. Compiling, Preprocessor, Formatting, Comments.

Introduction.

Compiling Cprograms.

Using Preprocessor Directives.

Copy Code into a Program.

Program Constants.

Statement Formatting.

Using White Space.

Inserting Comments.

Summary.



3. Defining Data in C.

Introduction.

Data Names in C.

Mixed Case in Data Names: Don't Do It.

Data Types.

Common C Data Types.

COBOL Data Types and Equivalent C Data Types.

A single character.

Alphanumerics of two or more characters (string).

Integer--no decimal places.

Large integer--no decimal places.

Large decimal number.

Inadequate decimal number.

Numeric literals and constants.

Record or group item.

Record or group item template.

Group item within another group item.

Alternate method for group item template.

Data type for "no value."

Small integer.

Where to Declare Data.

DataType Modifiers.

Storage Classes.

Automatic.

Static.

External.

Register.

Summary.



4. Instructions, Keywords, and Function Calls.

Introduction.

Why C Uses Few Keywords.

When to Use Keywords/Symbol Operators and When to Use Functions.

Functions Compared to COBOL Subprograms.

Return Value of a Function.

Function Prototypes (Call Parameter Templates).

Library Function Prototypes.

Coercion and Conversion of Parameters.

Summary.



5. Terminal Input/Output.

Introduction.

Terminal I/O.

Format and display field(s) on the terminal.

Format specifiers.

Carriage control.

Displaying special characters.

Read a string of characters from the terminal.

Read one character from the terminal.

Read and format numbers and/or characters from the terminal.

Convert an alphanumeric to an integer.

Convert an alphanumeric to a long integer.

Convert an alphanumeric to a decimal number.

Convert a single character to lowercase.

Convert a single character to uppercase.

Summary.



6. File Input/Output.

Introduction.

Sequential Files.

File Handling in C.

Variable-Length and Fixed-Length Records.

Opening and Closing Files.

Open a sequential file.

Close a sequential file.

Reading Variable-Length Files.

Read a string of characters from a file.

Format and extract field(s) from a string.

Read one character from a file.

Printing and Writing Variable Length Files.

Format and write field(s) to a file.

Format specifiers.

How long is a record.

Carriage control.

Printing special characters.

FILLER.

Fixed-Length Record Processing.

Write a fixed-length record to a file.

Read a fixed-length record from a file.

AFinal Comment.

Summary.



7. Moving Data.

Introduction.

Moving Numeric and Single-Character Data.

Move a number (assign).

Move a single character (assign).

Move a structure (assign).

Moving String Data.

Move a string.

Move the first <EM>n </EM>characters of a string.

Find the length of a string.

Find the defined length of any data item.

Move and format strings and/or numbers into a string.

Append one string to another one.

Summary.



8. Arithmetic.

Introduction.

Types of Business Arithmetic in C.

C and COBOL Arithmetic Operators/Keywords.

Common Arithmetic Mistakes in C.

Intermediate Results.

Overflow.

Rounding.

Basic Arithmetic--"Compute" Style.

Addition.

Subtraction.

Multiplication.

Division.

Remainder (modulus).

Basic Arithmetic--"Adt To" Style.

Add To.

Subtract From.

Multiply By.

Divide Into.

Remainder Into.

Incrementing/Decrementing a Data Item.

Absolute Value of a Number.

Introduction.

Absolute value of an integer (int).

Absolute value of a long integer (long).

Absolute value of a double (double).

Summary.



9. If, Case (EVALUATE), and Class Tests.

Introduction.

Test one or more conditions.

COBOL and C If Statements Compared.

Numeric and Single-Character Comparisons.

Equal.

Not equal.

Greater than.

Greater than or equal.

Less than.

Less than or equal.

Test Condition Delimiters.

And and Or.

If . . . then.

Parentheses.

Nested if statements.

Curly braces and why you should use them.

Other Features.

NEXTSENTENCE(Do nothing).

Implied subjects.

Condition-names.

String Comparisons.

Case (EVALUATE) Statements.

Class Test.

Test a single character for.

Alphabetic.

Alphanumeric.

ASCII character range.

ASCII control character.

C language white space.

Decimal digit.

Hexadecimal digit.

Lowercase letter.

Printable character.

Printable character but not a space.

Punctuation character.

Uppercase letter.

Summary.



10. Flow of Control Statements.

Introduction.

IExecute a loop while a condition is true, while varying the condition.

(PERFORM ... VARYING ... UNTIL).

IExecute a loop while a condition is true.

(PERFORM UNTIL).

IInfinite loops (intentional).

ICall a function which has no parameters.

(PERFORM).

ICall a function with parameters.

(CALL).

IGo to the bottom of a loop.

ITerminate a loop and go to the following statement.

IGO TO.

IReturn control to calling function or to operating system.

(GOBACK/STOP RUN).

IReturn control to operating system.

(STOP RUN).

Isummary.



11. Calling Functions (Subprograms).

Introduction.

Files and Functions.

Scope of Data.

Three Types of Functions.

C Functions that work like COBOL subprograms.

C Functions that work like COBOL paragraphs.

C Functions that work like COBOL "Super Paragraphs" or "Super Subprograms" Program Global Data.

Function Calls.

Memory Between Function Calls.

Parameter Passing.

Pointers Explained in English.

Using a Pointer as a Parameter in Another Call.

Return Value of a Function--Part 2.

Calling Functions Using Elementary Data Items.

Calling Functions Using Structures.

Calling Functions Using Members of Structures.

Summary of Rules for Passing Parameters.

Run-Time Parameters.

Summary.



12. Table Handling.

Introduction.

What is an Array?

Tables in COBOL.

Arrays in C.

Subscript Notation.

Relative Subscripting.

Offset versus Count.

Subscript 0 and Subscript 1.

Memory Contents at Run Time.

Running Off the End of an Array.

Defining Arrays in C.

One-Dimensional Array Definition.

Multidimensional Array Definition.

Character Array (String) Definition.

String Array Definition.

Structure Array Definition.

Initializing Arrays.

Default Initialization.

Initialization at Compile Time.

Initialization by Assigning Values at Run Time.

Memory For Arrays.

Allocating a Fixed Amount of Memory at Compile Time.

Allocating a Fixed Amount of Memory at Run Time.

Linked Lists: Allocating a Variable Amount of Memory at Run Time.

Allocate memory at run time.

Return allocated memory to the operating system.

Summary.



13. C Standards for a Business Environment.

Introduction.

Why Have Standards?

How Large Should a Standards Document Be?

Who Should Develop Standards and How?

Who Should Enforce Standards and How?

Portability.

References.

A Proposed Set of C Standards for a Business Environment.

Program Organization.

Source Code Header File.

Include Files.

#define Statements.

Program Constant Fields.

typedef Statements.

Function Prototypes.

Program Variables.

Structures.

Structure typedef Names.

Data Names.

Function Names.

Comments.

Functions.

Function Documentation.

Precedence of Operators.

One Statement per Line.

Line Length.

Indentation.

White Space Between Lines.

White Space Within a Line.

Increment/Decrement Operator.

if Statements.

switch Statements.

for Statements.

Parameters.

Program Global Variables.

while Statements.

printf()and fprintf() Statements.

Banned Items, Constructs, and Techniques.

Summary.



14. C++, or What's That OOP on Your Tie?

Introduction.

References.

C++ as a Better C.

Tighter Compiler.

Reduced Need for the Preprocessor.

More Convenient Comment Symbol.

Prototypes with Teeth.

Superior Call Parameter Handling.

Consistency in Parameter Use.

New I/O functions.

C++ as a Better C: Summary.

Beyond C: C++ as an Object-Oriented Programming.

Language.

Class: A Data Type Plus the Code That Manipulates It.

Class Libraries: Buy Them, Don't Write Them.

Encapsulation: Wrapping Code Around Data.

Public and Private Members of a Class.

Allocating and Releasing Memory.

Constructors And Destructors.

A Program that Uses the string Class.

Header File for the string Class.

Function File for the string Class.

Class Summary.

Inheritance: The Path to Code Reuse.

Polymorphism: How a Function Can Be in Two Places at Once.

Ad Hoc Polymorphism: Operator Overloading.

Ad Hoc Polymorphism: Function Overloading.

Inclusion Polymorphism: Function Overloading Across Derived Classes.

Persistence and the Problem Of C++.

Summary.



Appendices.

A. Official ANSI C Keyword List.

B. Actual C Keyword List.

C. ASCII Character Codes.

D. Powers of 2.

E. Precedence and Associativity of Operators.

F. Business Utility Programs.

1. A Business Rounding Routine.

2. A Business Truncation Routine.

3. Format a double as Dollars with Commas.

4. Format a double as an Integer with Commas.

G. COBOL to CCross-Reference.

H. Obtaining Code for Examples, Business UtilityPrograms, and Standards.



Index. 0805316604T04062001

Preface

This book was born of rage.

When I first tried to learn the C language in 1985, I could not find a book that made sense to me. I had been designing business systems and programming COBOL for more than 15 years. All the books on C that I found were "self-referential." That is to say, the authors had been writing C for so long that they had forgotten what it was like not to know it. I gave up after a few months. I was enraged that nobody had written a readable and useful book.

One day in 1988 my client, Rob Gillette, dropped 20 C programs on my desk and said, "Here, Jim, learn C and finish this subsystem." I went back to the bookstore and found the books to be a little better than three years before, but still not very good. I learned C, but it was a painful experience.

In 1991 I began working on business systems being developed in C. It was at this time I realized that I could write the book I had been looking for: C for COBOL Programmers.

C is just another language. Much of it works like COBOL, but with symbols instead of words. Parts of C have assumptions different from COBOL, and parts have rules different from COBOL. The purpose of this book is to use your knowledge of COBOL to teach you C. The book shows you where C works the same way as COBOL and shows you where it's different. It also focuses on the parts of C used most often in business systems.

C has some very nice features and some that are a real pain in the neck, just like COBOL.

Come on, jump in! The water's not that cold!



0805306604P04062001

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020