Академический Документы
Профессиональный Документы
Культура Документы
Strings
Instructor:
KunMaoChao
(
)
Strings
C implements the string data structure using
arrays of type char.
You have already used the string extensively.
printf(This program is terminated!\n);
#define ERR_Message Error!!
92
Copyright2004Pearson
[13]
e \0 ?
93
Arrays of Strings
An array of strings is a two-dimensional array of
characters in which each row is one string.
char names[People][Length];
char month[5][10] = {January,
February, March, April,
May};
Copyright2004Pearson
94
Input/Output of a String
The placeholder %s is used to represent string
arguments in printf and scanf.
printf(Topic: %s\n, string_var);
95
Copyright2004Pearson
96
Copyright2004Pearson
97
Copyright2004Pearson
98
Copyright2004Pearson
99
Purpose
Example
strcpy
Makes a copy of a
string
strcat
strcmp
strlen
strtok
Copyright2004Pearson
strcpy(s1, Hi);
strcmp(s1, Hu);
strtok(Hi, Chao,
,);
910
Copyright2004Pearson
912
Copyright2004Pearson
913
914
\0
StringQ
915
916
Returned Value
Example
Hello< Hi
str1 = str2 0
Hi = Hi
Hi > Hello
Copyright2004Pearson
917
918
919
920
921