Programming Tools Guide
Chapter 2, C compilation system

String, character, environment and memory routines

String, character, environment and memory routines

These are functions and macros that perform a variety of tasks:

The following tables list functions and macros that perform the first three tasks.

Table 2-3, ``String operations'' lists string-handling functions that appear in string(S). Programs that use these functions should include the header file string.h. 

Table 2-3 String operations

 strcat    Append a copy of one string to the end
           of another.
 strncat   Append no more than a given amount of
           characters from one string to the end of
           another.
 strcmp    Compare two strings.  Returns an integer
           less than, greater than, or equal to 0
           to show that one is lexicographically
           less than, greater than, or equal to the
           other.
 strncmp   Compare no more than a given amount of
           characters from the two strings.
           Results are otherwise identical to
           strcmp.
 strcpy    Copy a string.
 strncpy   Copy a given amount of characters from
           one string to another.  The destination
           string will be truncated if it is longer
           than the given amount of characters, or
           padded with null characters if it is
           shorter.
 strdup    Return a pointer to a newly allocated
           string that is a duplicate of a string
           pointed to.
 strchr    Return a pointer to the first occurrence
           of a character in a string, or a null
           pointer if the character is not in the
           string.
 strrchr   Return a pointer to the last occurrence
           of a character in a string, or a null
           pointer if the character is not in the
           string.
 strlen    Return the number of characters in a
           string.
 strpbrk   Return a pointer to the first occurrence
           in one string of any character from the
           second, or a null pointer if no
           character from the second occurs in the
           first.
 strspn    Return the length of the initial segment
           of one string that consists entirely of
           characters from the second string.
 strcspn   Return the length of the initial segment
           of one string that consists entirely of
           characters not from the second string.
 strstr    Return a pointer to the first occurrence
           of the second string in the first
           string, or a null pointer if the second
           string is not found.
 strtok    Break up the first string into a
           sequence of tokens, each of which is
           delimited by one or more characters from
           the second string.  Return a pointer to
           the token, or a null pointer if no token
           is found.
Table 2-4, ``Classifying 8-bit character-coded integer values'' lists functions and macros that classify 8-bit character-coded integer values. These routines appear in toascii(S) and ctype(S). Programs that use these routines should include the header file ctype.h. 

Table 2-4 Classifying 8-bit character-coded integer values

 isalpha    Is c a letter?
 isupper    Is c an uppercase letter?
 islower    Is c a lowercase letter?
 isdigit    Is c a digit [0-9]?
 isxdigit   Is c a hexadecimal digit [0-9], [A-F],
            or [a-f]?
 isalnum    Is c alphanumeric (a letter or digit)?
 isspace    Is c a space, horizontal tab, carriage
            return, new-line, vertical tab, or
            form-feed?
 ispunct    Is c a punctuation character (neither
            control nor alphanumeric)?
 isprint    Is c a printing character?
 isgraph    Same as isprint except false for a
            space.
 iscntrl    Is c a control character or a delete
            character?
 isascii    Is c an ASCII character?
 toupper    Change lowercase to uppercase.
 _toupper   Macro version of toupper.
 tolower    Change uppercase to lowercase.
 _tolower   Macro version of tolower.
 toascii    Turn off all bits that are not part of
            a standard ASCII character; intended
            for compatibility with other systems.
Table 2-5, ``Converting characters, integers, or strings'' lists functions and macros that are used to convert characters, integers, or strings from one representation to another. The left column contains the name that appears at the top of the manual page; the other names in the same row are related functions or macros described on the same manual page. Programs that use these routines should include the header file stdlib.h. 

Table 2-5 Converting characters, integers, or strings

 a64l      l64a              Convert between long integer
                             and base-64 ASCII string.
 ecvt      fcvt    gcvt      Convert floating point number
                             (long double
           ecvtl   fcvtl     number) to string.
                   gcvtl
 l3tol     ltol3             Convert between 3-byte packed
                             integer and long integer.
 strtod    atof    strtold   Convert string to double-
                             precision number.
 strtol    atol    atoi      Convert string to integer.
 strtoul                     Convert string to unsigned
                             long.