Fall 2014
Instructor: Reza Entezari-Maleki
Email: entezari@ce.sharif.edu
Sharif University of Technology
1
Fundamentals of Programming
Session 23
These slides have been created using Deitel’s slides
Fundamentals of Programming Session 23 Instructor: Reza - - PowerPoint PPT Presentation
Fundamentals of Programming Session 23 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2014 These slides have been created using Deitels slides Sharif University of Technology Outlines String-Conversion Functions
Fall 2014
Sharif University of Technology
1
Session 23
These slides have been created using Deitel’s slides
2
This section presents the string-conversion functions
These functions convert strings of digits to integer and
Figure 8.5 summarizes the string-conversion functions. Note the use of const to declare variable nPtr in the
3
4
5
6
7
This
Figure
8
9
10
11
12
The string-handling library (<string.h>) provides
This section presents the string-manipulation functions
The functions are summarized in Fig. 8.17. Every function—except for strncpy—appends the
13
14
15
16
This section presents the string-handling library’s
Fig. 8.20 contains their prototypes and a brief
17
18
19
20
This section presents the functions of the string-
The functions are summarized in Fig. 8.22. The
21
22
23
24
25
Function strtok (Fig. 8.29) is used to break a
A token is a sequence of characters separated by
For example, in a line of text, each word can be
26
27
28
The two remaining functions of the string-handling
Figure
29
30
31
32
Structures—sometimes referred to as aggregates—
Structures may contain variables of many different
Consider the following structure definition:
struct
struct card { card { char char *face; *face; char char *suit; *suit; }; };
33
The definition of struct card contains members face
Structure members can be variables of the primitive data
As another example consider the following structure:
struct
struct employee { employee { char char firstName firstName[ [ 20 20 ]; ]; char char lastName lastName[ [ 20 20 ]; ]; int int age; age; char char gender; gender; double double hourlySalary hourlySalary; }; };
34
A structure cannot contain an instance of itself. For example, a variable of type struct employee cannot be
declared in the definition for struct employee.
A pointer to struct employee, however, may be included. For example,
struct
struct employee2 { employee2 { char char firstName firstName[ 20 ]; [ 20 ]; char char lastName lastName[ 20 ]; [ 20 ]; int int age; age; char char gender; gender; double double hourlySalary hourlySalary; ; struct struct employee2 person; employee2 person; /* ERROR */ /* ERROR */ struct struct employee2 * employee2 *ePtr ePtr; ; /* pointer */ /* pointer */ }; };
struct employee2 contains an instance of itself (person),
which is an error.
35