Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

memory: memccpy, memchr, memcmp, memcpy, memset, bcopy

NCstring

NLstring

mbstring

wcstring

swab



STRING(3,L)                 AIX Technical Reference                 STRING(3,L)



-------------------------------------------------------------------------------
string



PURPOSE

Performs operations on strings.

LIBRARY

Standard C Library (libc.a)

SYNTAX

#include <string.h>




                char *strcat (s1, s2)       size_t strlen (s)
                char *s1, *s2;              char *s;

                char *strncat (s1, s2, n)   char *strchr (s, c)
                char *s1, *s2;              char *s;
                size_t n;                   int c;

                int strcmp (s1, s2)         char *strrchr (s, c)
                char *s1, *s2;              char *s;
                                            int c;
                int strncmp (s1, s2, n)
                char *s1, *s2;              char *strpbrk (s1, s2)
                size_t n;                   char *s1, *s2;

                char *strcpy (s1, s2)       size_t strspn (s1, s2)
                char *s1, *s2;              char *s1, *s2;

                char *strncpy (s1, s2, n)   size_t strcspn (s1, s2)
                char *s1, *s2;              char *s1, *s2;
                size_t n;
                                            char *strtok (s1, s2)
                                            char *s1, *s2;



DESCRIPTION

Note:  For subroutines which perform operations on wide and multibyte
       characters, refer to "wcstring" and "mbstring."

The string subroutines copy, compare, and append strings in memory, and they
determine such things as location, size, and existence of strings in memory.



Processed November 7, 1990        STRING(3,L)                                 1





STRING(3,L)                 AIX Technical Reference                 STRING(3,L)




The parameters s1, s2 and s point to strings.  A string is an array of
characters terminated by a NULL character.  The subroutines strcat, strncat,
strcpy, and strncpy all alter s1.  They do not check for overflow of the array
pointed to by s1.  All string movement is performed character by character and
starts at the left.  Overlapping moves toward the left work as expected, but
overlapping moves to the right may give unexpected results.  All of these
subroutines are declared in the string.h header file.

The strcat subroutine adds a copy of the string pointed to by the s2 parameter
to the end of the string pointed to by the s1 parameter.  The strcat subroutine
returns a pointer to the NULL-terminated result.

The strncat subroutine copies at most n bytes of s2 to the end of the string
pointed to by the s1 parameter.  Copying stops before n bytes if a NULL
character is encountered in the s2 string.  The strncat subroutine returns a
pointer to the NULL-terminated result.

The strcmp subroutine lexicographically compares the string pointed to by the
s1 parameter to the string pointed to by the s2 parameter.  The strcmp
subroutine uses native character comparison, which may be signed or unsigned.
The strcmp subroutine returns a value that is:

    Less than 0       If s1 is less than s2
    Equal to 0        If s1 is equal to s2
    Greater than 0    If s1 is greater than s2.

The strncmp subroutine makes the same comparison as strcmp, but it compares at
most n pairs of characters.

The strcpy subroutine copies the string pointed to by the s2 parameter to the
character array pointed to by the s1 parameter.  Copying stops when the NULL
character is copied.  The strcpy subroutine returns the value of the s1
parameter.

The strncpy subroutine copies n bytes from the string pointed to by the s2
parameter to the character array pointed to by the s1 parameter.  If s2 is less
than n characters long, then strncpy pads s1 with trailing NULL characters to
fill n bytes.  If s2 is n or more characters long, then only the first n
characters are copied and the result is not terminated with a NULL character.
The strncpy subroutine returns the value of the s1 parameter.

The strlen subroutine returns the number of characters in the string pointed to
by the s parameter, not including the terminating NULL character.

The strchr subroutine returns a pointer to the first occurrence of the
character specified by the c parameter in the string pointed to by the s
parameter.  A NULL pointer is returned if the character does not occur in the
string.  The NULL character that terminates a string is considered to be part
of the string.





Processed November 7, 1990        STRING(3,L)                                 2





STRING(3,L)                 AIX Technical Reference                 STRING(3,L)



The strrchr subroutine returns a pointer to the last occurrence of the
character specified by the c parameter in the string pointed to by the s
parameter.  A NULL pointer is returned if the character does not occur in the
string.  The NULL character that terminates a string is considered to be part
of the string.

The strpbrk subroutine returns a pointer to the first occurrence in the string
pointed to by the s1 parameter of any character from the string pointed to by
the s2 parameter.  A NULL pointer is returned if no character matches.

The strspn subroutine returns the length of the initial segment of the string
pointed to by the s1 parameter that consists entirely of characters from the
string pointed to by the s2 parameter.

The strcspn subroutine returns the length of the initial segment of the string
pointed to by the s1 parameter that consists entirely of characters not from
the string pointed to by the s2 parameter.

The strtok subroutine returns a pointer to an occurrence of a text token in the
string pointed to by the s1 parameter.  The s2 parameter specifies a set of
token delimiters.  If the s1 parameter is anything other than NULL, then the
strtok subroutine reads the string pointed to by the s1 parameter until it
finds one of the delimiter characters specified by the s2 parameter.  It then
stores a NULL character into the string, replacing the delimiter, and returns a
pointer to the first character of the text token.  The strtok subroutine keeps
track of its position in the string so that subsequent calls with a NULL s1
parameter step through the string.  The delimiters specified by the s2
parameter can be changed for subsequent calls to strtok.  When no tokens remain
in the string pointed to by the s1 parameter, the strtok subroutine returns a
NULL pointer.

RELATED INFORMATION

In this book:  "memory: memccpy, memchr, memcmp, memcpy, memset, bcopy,"
"NCstring,"  "NLstring,"  "mbstring," "wcstring," and  "swab."




















Processed November 7, 1990        STRING(3,L)                                 3



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026