Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ string(3) — AIX/RT 2.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

memccpy, memchr, memcmp, memcpy, memset, bcopy

NCstring

NLstring

swab

string

Purpose

     Performs operations on strings.

Library

     Standard C Library (libc.a)

Syntax

     #include <string.h>

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

     char *strncat (s1, s2, n)                 char *strchr (s, c)
     char *s1, *s2;                            char *s, c;
     int n;
                                               char *strrchr (s, c)
     int strcmp (s1, s2)                       char *s, c;
     char *s1, *s2;
                                               char *strpbrk (s1, s2)
     int strncmp (s1, s2, n)                   char *s1, *s2;
     char *s1, *s2;
     int n;                                    int strspn (s1, s2)
                                               char *s1, *s2;
     char *strcpy (s1, s2)
     char *s1, *s2;                            int strcspn (s1, s2)
                                               char *s1, *s2;
     char *strncpy (s1, s2, n)
     char *s1, *s2;                            char *strtok (s1, s2)
     int n;                                    char *s1, *s2;
     Description

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

     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 char-
     acter 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 charac-
     ters 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 param-
     eter.

     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.

     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 param-
     eter.  The s2  parameter specifies a set  of token delim-
     iters.  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 delim-
     iter, 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 delim-
     iters 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 subrou-
     tine returns a NULL pointer.

     Related Information

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

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