0% found this document useful (0 votes)
8 views30 pages

CEII Lecture 2

Uploaded by

alihalawa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views30 pages

CEII Lecture 2

Uploaded by

alihalawa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

EEC 124

Computer Engineering II

Lecture 2
C-Strings (Character Arrays)
Character array: An array whose components are of type char.

The first character in the ASCII character set is the null character,
which is nonprintable. Also, recall that in C++, the null character is
represented as '\0'

The following are examples of C-strings:


"John L. Johnson"
"Hello there.“

From the definition of C-strings, it is clear that there is a difference


between 'A' and "A". The first one is character A; the second is C-
string A. Because C-strings are null terminated, "A" represents two
characters: 'A' and '\0'.

Computer Engineering II Dr. Mohamed A. Torad 2


C-Strings (Character Arrays)

Computer Engineering II Dr. Mohamed A. Torad 3


C-Strings (Character Arrays)

C++ provides a set of functions that can be used for C-string


manipulation. The header file cstring describes these functions.
We often use three of these functions:
strcpy (string copy, to copy a C-string into a C-string variable—that is,
assignment)
strcmp (string comparison, to compare C-strings)
strlen (string length, to find the length of a C-string).

Computer Engineering II Dr. Mohamed A. Torad 4


C-Strings (Character Arrays)
Table 9-1 summarizes these functions.

Computer Engineering II Dr. Mohamed A. Torad 5


C-Strings (Character Arrays)

Computer Engineering II Dr. Mohamed A. Torad 6


Reading and Writing Strings

Computer Engineering II Dr. Mohamed A. Torad 7


Reading and Writing Strings

Computer Engineering II Dr. Mohamed A. Torad 8


Reading and Writing Strings

Computer Engineering II Dr. Mohamed A. Torad 9


Specifying Input/Output Files at Execution Time

Computer Engineering II Dr. Mohamed A. Torad 10


Parallel Arrays
Two (or more) arrays are called parallel if their corresponding
components hold related information.

Computer Engineering II Dr. Mohamed A. Torad 11


Parallel Arrays

Computer Engineering II Dr. Mohamed A. Torad 12


Two- and Multidimensional Arrays

Computer Engineering II Dr. Mohamed A. Torad 13


Two- and Multidimensional Arrays

Computer Engineering II Dr. Mohamed A. Torad 14


Accessing Array Components

Computer Engineering II Dr. Mohamed A. Torad 15


Two-Dimensional Array Initialization During Declaration

Computer Engineering II Dr. Mohamed A. Torad 16


Two-Dimensional Arrays and Enumeration Types

Computer Engineering II Dr. Mohamed A. Torad 17


PROCESSING TWO-DIMENSIONAL ARRAYS

Computer Engineering II Dr. Mohamed A. Torad 18


PROCESSING TWO-DIMENSIONAL ARRAYS

Computer Engineering II Dr. Mohamed A. Torad 19


PROCESSING TWO-DIMENSIONAL ARRAYS

Computer Engineering II Dr. Mohamed A. Torad 20


PROCESSING TWO-DIMENSIONAL ARRAYS

Computer Engineering II Dr. Mohamed A. Torad 21


PROCESSING TWO-DIMENSIONAL ARRAYS

Computer Engineering II Dr. Mohamed A. Torad 22


Passing Two-Dimensional Arrays as Parameters to Functions

Computer Engineering II Dr. Mohamed A. Torad 23


Passing Two-Dimensional Arrays as Parameters to Functions

Computer Engineering II Dr. Mohamed A. Torad 24


Passing Two-Dimensional Arrays as Parameters to Functions

Computer Engineering II Dr. Mohamed A. Torad 25


Passing Two-Dimensional Arrays as Parameters to Functions

Computer Engineering II Dr. Mohamed A. Torad 26


Arrays of Strings and C-Strings (Character Arrays)

Computer Engineering II Dr. Mohamed A. Torad 27


Arrays of Strings and C-Strings (Character Arrays)

Computer Engineering II Dr. Mohamed A. Torad 28


Another Way to Declare a Two-Dimensional Array

Computer Engineering II Dr. Mohamed A. Torad 29


Multidimensional Arrays

Computer Engineering II Dr. Mohamed A. Torad 30

You might also like