Eee0115 7
Eee0115 7
Chapter 8: C Characters
and Strings
C How to Program
1 Deitel & Deitel
2
Outline
Fundamentals of Strings and Characters
Character-Handling Library
String-Conversion Functions
Standard Input/Output Library Functions
String Manipulation Functions
String Comparison Functions
3
Character-Handling Library
19 printf( "%s\n%s%s\n%s%s\n%s%s\n\n",
20 "According to isalnum:",
21 isalnum( 'A' ) ? "A is a " : "A is not a ",
22 "digit or a letter",
23 isalnum( '8' ) ? "8 is a " : "8 is not a ",
24 "digit or a letter",
25 isalnum( '#' ) ? "# is a " : "# is not a ",
26 "digit or a letter" );
27
28 printf( "%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n",
29 "According to isxdigit:",
30 isxdigit( 'F' ) ? "F is a " : "F is not a ",
31 "hexadecimal digit",
32 isxdigit( 'J' ) ? "J is a " : "J is not a ",
33 "hexadecimal digit",
34 isxdigit( '7' ) ? "7 is a " : "7 is not a ",
35 "hexadecimal digit",
36 isxdigit( '$' ) ? "$ is a " : "$ is not a ",
7
Character-Handling Library
37 "hexadecimal digit",
38 isxdigit( 'f' ) ? "f is a " : "f is not a ",
39 "hexadecimal digit" );
40
41 return 0; /* indicates successful termination */
42
43 } /* end main */
According to isdigit:
8 is a digit
# is not a digit
According to isalpha:
A is a letter
b is a letter
& is not a letter
4 is not a letter
According to isalnum:
A is a digit or a letter
8 is a digit or a letter
# is not a digit or a letter
According to isxdigit:
F is a hexadecimal digit
J is not a hexadecimal digit
7 is a hexadecimal digit
$ is not a hexadecimal digit
f is a hexadecimal digit
8
int puts( const char *s ); Prints the string s followed by a newline character. Returns
a non-zero integer if successful, or EOF if an error occurs.
strcmp(s1, s2) = 0
strcmp(s1, s3) = 1
strcmp(s3, s1) = -1
strncmp(s1, s3, 6) = 0
strncmp(s1, s3, 7) = 1
strncmp(s3, s1, 7) = -1