Networking Chapter 10 Homework Use Few Examples Show How Use Print f3 Use Examples And Table 105

subject Type Homework Help
subject Pages 9
subject Words 2121
subject Authors Michael Palmer

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
A Guide to Unix Using Linux, Fourth Edition 10-1
Chapter 10
Developing UNIX/Linux Applications in C and C++
At a Glance
Instructor’s Manual Table of Contents
Overview
Objectives
Teaching Tips
Quick Quizzes
page-pf2
A Guide to Unix Using Linux, Fourth Edition 10-2
Lecture Notes
Overview
In Chapter 10, your students learn how to write, compile, and execute basic C programs.
They also learn how to use the make utility. The make utility is a UNIX/Linux
software development tool that controls compilation as you make changes and
Chapter Objectives
Understand basic elements of C programming
Debug C programs
Create, compile, and test C programs
Use the make utility to revise and maintain source files
Identify differences between C and C++ programming
Teaching Tips
Introducing C Programming
1. Explain that UNIX was developed and refined in the C language. Stress that since C is
native to UNIX/Linux, it works best as an application development tool. For example,
daemons are written in C.
Besides Kernighan and Ritchie, Ken Thompson, another AT&T Bell Labs
2. Note that C is a compiled language.
Creating a C Program
1. Use Figure 10-1 to describe how to create a C program, starting from the source file and
ending in the executable program. The roles of the preprocessor, compiler, and linker
should be briefly described.
page-pf3
A Guide to Unix Using Linux, Fourth Edition 10-3
In some instances, the linker is not a separate tool because the compiler can be
C Keywords
1. Explain that keywords have special meanings and cannot be used as names for variables
or functions.
2. Table 10-1 shows the C language keywords.
Note that Table 10-1 contains standard keywords for ANSI C. GNU C adds
The C Library
2. Introduce the term function call.
3. Note that the linker joins the code of the library function with a program’s object code
Program Format
2. Stress that every C program must have a main() function. Provide an example of C code
that shows a very basic main() function.
Including Comments
1. Use an example to show how to include comments in a C program.
page-pf4
A Guide to Unix Using Linux, Fourth Edition 10-4
Using the Preprocessor #include Directive
1. Use the example provided in the book (see Figure 10-2) to explain what a preprocessor
2. Note that the file stdio.h is called a header file.
Specifying Data Types
1. Use Tables 10-2 and 10-3 to describe the data types available in C.
2. Note that a variable’s data type determines upper and lower limits of its range of values.
Stress that the exact limits of ranges vary among compilers and hardware platforms.
Character Constants
1. Explain that characters are represented internally in a single byte of the computer’s
Using Strings
1. When explaining how to use strings in C, the following points are important to mention:
a. A string is a group of characters.
2. Stress that a character array of size n can hold a string that has n 1 characters. The
extra character holds the null character.
page-pf5
A Guide to Unix Using Linux, Fourth Edition 10-5
Including Identifiers
1. Explain that identifiers are names given to variables and functions.
3. Stress that the following rules should be followed when naming identifiers.
a. The first character must be a letter or an underscore.
4. Provide examples of useful and valid identifier names.
Declaring Variables
2. Use an example to show that you can declare multiple variables of the same type on the
same line.
3. Provide an example to show how to initialize variables with values at the time they are
declared.
Understanding the Scope of Variables
2. Use a couple of examples to show what a local or automatic variable is, and what a
global or external variable is. Make sure students understand the difference of scope
page-pf6
A Guide to Unix Using Linux, Fourth Edition 10-6
Using Math Operators
1. Use Table 10-4 and a few examples to show how to use math operators in C.
2. Make sure students understand the difference between ++count and count++.
Generating Formatted Output with printf()
1. Describe the syntax of the printf() function.
3. Use examples and Table 10-5 to describe the most common C format specifiers.
The printf function is a powerful and versatile tool for programmers. However,
note that a malicious user may, in some instances, be able to use format
specifiers for printf to launch a format string attack on a computer that can crash
Quick Quiz 1
1. ____________________ are specialized system processes, such as network printing,
that run in the background.
2. The C ____________________ makes modifications to your program, such as
including the contents of other files and creating constant values.
3. The C ____________________ consists of functions that perform file, screen, and
keyboard operations, as well as many other tasks.
4. In C, the ____________________ symbol denotes the beginning of a comment.
page-pf7
A Guide to Unix Using Linux, Fourth Edition 10-7
Using the C Compiler
1. Describe the syntax of the gcc program.
Using the if Statement
2. Use a couple of examples to show how to use if and if-else statements in a C program.
Using C Loops
1. Provide examples for each of the three looping mechanisms in C: for, while, and do-
while.
Defining Functions
2. Use the example provided in the book to show how to define and use a function.
3. Describe the role of a function prototype. Explain that the word void before the name of
the function (in its declaration or definition) indicates that the function does not return a
value.
Using Function Arguments
2. Use the example provided in the book to show how to use function arguments in C.
Using Function Return Values
1. Use the example provided in the book to show how to use function return values in C.
page-pf8
A Guide to Unix Using Linux, Fourth Edition 10-8
Working with Files in C
1. Provide code examples to explain the following aspects of working with files in C:
a. C file input/output is designed to use file pointers.
Using the make Utility to Maintain Program Source Files
1. Describe the advantages of breaking down the code of a program into smaller modules,
instead of working with one large source code file.
3. Explain how make can be used to solve the problem described above.
5. Describe the syntax of make and use a sample makefile to show how to define basic
make rules.
6. Use Figure 10-3 to show how to make and run a sample program.
page-pf9
A Guide to Unix Using Linux, Fourth Edition 10-9
Debugging Your Program
1. Provide examples of typical syntax errors. Show sample compiler output for these
errors. Note that the compiler generally produces more error lines than the number of
2. Describe the steps that can be followed to correct syntax errors within a program, such
as: (1) record the line numbers indicated in compiler output; (2) fix the errors one by
one (starting with the first line number); and (3) save and recompile.
Creating a C Program to Accept Input
1. Describe the syntax of the scanf() function.
3. Provide some examples to show how to use scanf(). Specifically, note that an
Quick Quiz 2
1. The command for the C compiler in Linux operating systems is
____________________.
2. Using the ____________________ loop is best when you know the number of times
that the loop is to perform.
3. A function ____________________ tells the compiler about the function before the
code for the function is fully defined.
4. Make is a utility for maintaining updates to multiple programs in a project; it uses a
control file called a(n) ____________________.
page-pfa
A Guide to Unix Using Linux, Fourth Edition 10-10
Introducing C++ Programming
1. Explain the most important differences between C and C++. Introduce the following
terms: object-oriented programming, class, object, methods, and function overloading.
Creating a Simple C++ Program
1. Use the example provided in the book to show how to create a simple C++ program.
Specifically, note the use of // for comments and cout << to output text. In addition,
explain why the following lines are needed:
a. #include <iostream>
Creating a C++ Program that Reads a Text File
1. Use the example provided in the book to show how to create a C++ program that reads
a text file.
How C++ Enhances C Functions
1. Use the example provided in the book to show how to use C++ code to enhance C
page-pfb
A Guide to Unix Using Linux, Fourth Edition 10-11
Quick Quiz 3
1. Function ____________________ allows functions to respond to more than one set of
criteria and conditions.
2. A(n) ___________________ is a collection of data and a set of operations, called
methods, which manipulate the data.
3. C++ uses // to denote a(n) ____________________ line.
4. The ____________________ function is a part of the ifstream class and reports an
invalid condition with the file access.
Class Discussion Topics
1. Do any students in your class have previous object-oriented programming experience?
2. Remind students that like C, Awk supports a printf() function too. Discuss the
Additional Projects
1. What are C macros? Ask your students to do some research on the #define preprocessor
2. What are the differences between C strings (null-terminated arrays of characters) and
C++ strings (instances of the string class)? Tip: A useful resource is
Additional Resources
1. The C Preprocessor:
page-pfc
2. C Variable Types and Declarations:
Key Terms
assembler The program that is called by a compiler to translate assembly code into
object code.
assembly language A low-level language that provides maximum access to all the
computer’s devices, both internal and external. Writing an assembly language program
requires a great deal of coding and time.
automatic variable A variable declared inside a function and local to the function in
which it is declared.
C A programming language developed in part to overcome the disadvantages of
assembly language programming, which requires a great deal of coding and time. The
result is a high-level set of easy-to-understand instructions. UNIX was originally written
in assembly language but further developed and refined in C, largely due to the efforts
the screen output library function printf().
daemon A specialized system process that runs in the background. A daemon
accesses UNIX/Linux system code like any other part of the operating system.
decrement operator (--) A C/C++ arithmetic operator that decreases the value of a
variable by a specified amount.
page-pfd
function before the code for the function is fully defined.
header file A file containing the information the compiler needs to process standard
input or output statements.
identifiers The names given to variables and functions.
increment operator (++) A C/C++ arithmetic operator that increases the value of a
method A set of operations that manipulate data; a part of the new data class,
objects, used in the C++ programming language.
null character A single byte whose bits are all set to zero.
object code The binary instructions translated from program source code by a
compiler.
begins with the # symbol. An example is #include, which tells the preprocessor to
include another file or library in your program.
scope The part of the program in which a variable is defined and accessible. The
scope can be either inside or outside a function.
source code The program code that you create using an editor and that either is
page-pfe
A Guide to Unix Using Linux, Fourth Edition 10-14
Technical Notes for Hands-On Projects

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.