470 Appendix B The Standard C Library
A few other useful definitions from this header file are as follows:
Define Meaning
intptr_t Integer guaranteed to hold any pointer value
uintptr_t Unsigned integer guaranteed to hold any pointer value
intmax_t Largest signed integer type
uintmax_t Largest unsigned integer type
String Functions
The following functions perform operations on character arrays. In the description of
these routines,s,s1,and s2represent pointers to null-terminated character arrays,cis an
int,and nrepresents an integer of type size_t(defined in stddef.h). For the strnxxx
routines,s1and s2can point to character arrays that aren’t null-terminated.
To use any of these functions, you should include the header file <string.h>in your
program:
#include <string.h>
char *strcat (s1, s2)
Concatenates the character strings2to the end ofs1, placing a null character at the
end of the final string.The function returns s1.
char *strchr (s, c)
Searches the string sfor the first occurrence of the character c. If it is found, a point-
er to the character is returned; otherwise, a null pointer is returned.
int strcmp (s1, s2)
Compares strings s1and s2and returns a value less than zero if s1is less than s2,
equal to zero if s1is equal to s2, and greater than zero if s1is greater than s2.
char *strcoll (s1, s2)
Is like strcmp, except s1and s2are pointers to strings represented in the current
locale.
char *strcpy (s1, s2)
Copies the string s2to s1,returning s1.
21 0672326663 AppB 6/10/04 2:03 PM Page 470