Стандарт языка Си С99 TC (1113411), страница 61
Текст из файла (страница 61)
The initial characterof s2 overwrites the null character at the end of s1. If copying takes place betweenobjects that overlap, the behavior is undefined.Returns3The strcat function returns the value of s1.7.21.3.2 The strncat functionSynopsis1#include <string.h>char *strncat(char * restrict s1,const char * restrict s2,size_t n);Description2The strncat function appends not more than n characters (a null character andcharacters that follow it are not appended) from the array pointed to by s2 to the end ofthe string pointed to by s1. The initial character of s2 overwrites the null character at theend of s1. A terminating null character is always appended to the result.270) If copying269) Thus, if there is no null character in the first n characters of the array pointed to by s2, the result willnot be null-terminated.270) Thus, the maximum number of characters that can end up in the array pointed to by s1 isstrlen(s1)+n+1.§7.21.3.2Library327ISO/IEC 9899:TC3Committee Draft — Septermber 7, 2007WG14/N1256takes place between objects that overlap, the behavior is undefined.Returns3The strncat function returns the value of s1.Forward references: the strlen function (7.21.6.3).7.21.4 Comparison functions1The sign of a nonzero value returned by the comparison functions memcmp, strcmp,and strncmp is determined by the sign of the difference between the values of the firstpair of characters (both interpreted as unsigned char) that differ in the objects beingcompared.7.21.4.1 The memcmp functionSynopsis1#include <string.h>int memcmp(const void *s1, const void *s2, size_t n);Description2The memcmp function compares the first n characters of the object pointed to by s1 tothe first n characters of the object pointed to by s2.271)Returns3The memcmp function returns an integer greater than, equal to, or less than zero,accordingly as the object pointed to by s1 is greater than, equal to, or less than the objectpointed to by s2.7.21.4.2 The strcmp functionSynopsis1#include <string.h>int strcmp(const char *s1, const char *s2);Description2The strcmp function compares the string pointed to by s1 to the string pointed to bys2.Returns3The strcmp function returns an integer greater than, equal to, or less than zero,accordingly as the string pointed to by s1 is greater than, equal to, or less than the string271) The contents of ‘‘holes’’ used as padding for purposes of alignment within structure objects areindeterminate.
Strings shorter than their allocated space and unions may also cause problems incomparison.328Library§7.21.4.2WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC3pointed to by s2.7.21.4.3 The strcoll functionSynopsis1#include <string.h>int strcoll(const char *s1, const char *s2);Description2The strcoll function compares the string pointed to by s1 to the string pointed to bys2, both interpreted as appropriate to the LC_COLLATE category of the current locale.Returns3The strcoll function returns an integer greater than, equal to, or less than zero,accordingly as the string pointed to by s1 is greater than, equal to, or less than the stringpointed to by s2 when both are interpreted as appropriate to the current locale.7.21.4.4 The strncmp functionSynopsis1#include <string.h>int strncmp(const char *s1, const char *s2, size_t n);Description2The strncmp function compares not more than n characters (characters that follow anull character are not compared) from the array pointed to by s1 to the array pointed toby s2.Returns3The strncmp function returns an integer greater than, equal to, or less than zero,accordingly as the possibly null-terminated array pointed to by s1 is greater than, equalto, or less than the possibly null-terminated array pointed to by s2.7.21.4.5 The strxfrm functionSynopsis1#include <string.h>size_t strxfrm(char * restrict s1,const char * restrict s2,size_t n);Description2The strxfrm function transforms the string pointed to by s2 and places the resultingstring into the array pointed to by s1.
The transformation is such that if the strcmpfunction is applied to two transformed strings, it returns a value greater than, equal to, or§7.21.4.5Library329ISO/IEC 9899:TC3Committee Draft — Septermber 7, 2007WG14/N1256less than zero, corresponding to the result of the strcoll function applied to the sametwo original strings. No more than n characters are placed into the resulting arraypointed to by s1, including the terminating null character. If n is zero, s1 is permitted tobe a null pointer. If copying takes place between objects that overlap, the behavior isundefined.Returns3The strxfrm function returns the length of the transformed string (not including theterminating null character). If the value returned is n or more, the contents of the arraypointed to by s1 are indeterminate.4EXAMPLE The value of the following expression is the size of the array needed to hold thetransformation of the string pointed to by s.1 + strxfrm(NULL, s, 0)7.21.5 Search functions7.21.5.1 The memchr functionSynopsis1#include <string.h>void *memchr(const void *s, int c, size_t n);Description2The memchr function locates the first occurrence of c (converted to an unsignedchar) in the initial n characters (each interpreted as unsigned char) of the objectpointed to by s.Returns3The memchr function returns a pointer to the located character, or a null pointer if thecharacter does not occur in the object.7.21.5.2 The strchr functionSynopsis1#include <string.h>char *strchr(const char *s, int c);Description2The strchr function locates the first occurrence of c (converted to a char) in thestring pointed to by s.
The terminating null character is considered to be part of thestring.Returns3The strchr function returns a pointer to the located character, or a null pointer if thecharacter does not occur in the string.330Library§7.21.5.2WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC37.21.5.3 The strcspn functionSynopsis1#include <string.h>size_t strcspn(const char *s1, const char *s2);Description2The strcspn function computes the length of the maximum initial segment of the stringpointed to by s1 which consists entirely of characters not from the string pointed to bys2.Returns3The strcspn function returns the length of the segment.7.21.5.4 The strpbrk functionSynopsis1#include <string.h>char *strpbrk(const char *s1, const char *s2);Description2The strpbrk function locates the first occurrence in the string pointed to by s1 of anycharacter from the string pointed to by s2.Returns3The strpbrk function returns a pointer to the character, or a null pointer if no characterfrom s2 occurs in s1.7.21.5.5 The strrchr functionSynopsis1#include <string.h>char *strrchr(const char *s, int c);Description2The strrchr function locates the last occurrence of c (converted to a char) in thestring pointed to by s.
The terminating null character is considered to be part of thestring.Returns3The strrchr function returns a pointer to the character, or a null pointer if c does notoccur in the string.§7.21.5.5Library331ISO/IEC 9899:TC3Committee Draft — Septermber 7, 2007WG14/N12567.21.5.6 The strspn functionSynopsis1#include <string.h>size_t strspn(const char *s1, const char *s2);Description2The strspn function computes the length of the maximum initial segment of the stringpointed to by s1 which consists entirely of characters from the string pointed to by s2.Returns3The strspn function returns the length of the segment.7.21.5.7 The strstr functionSynopsis1#include <string.h>char *strstr(const char *s1, const char *s2);Description2The strstr function locates the first occurrence in the string pointed to by s1 of thesequence of characters (excluding the terminating null character) in the string pointed toby s2.Returns3The strstr function returns a pointer to the located string, or a null pointer if the stringis not found.
If s2 points to a string with zero length, the function returns s1.7.21.5.8 The strtok functionSynopsis1#include <string.h>char *strtok(char * restrict s1,const char * restrict s2);Description2A sequence of calls to the strtok function breaks the string pointed to by s1 into asequence of tokens, each of which is delimited by a character from the string pointed toby s2. The first call in the sequence has a non-null first argument; subsequent calls in thesequence have a null first argument.
The separator string pointed to by s2 may bedifferent from call to call.3The first call in the sequence searches the string pointed to by s1 for the first characterthat is not contained in the current separator string pointed to by s2. If no such characteris found, then there are no tokens in the string pointed to by s1 and the strtok function332Library§7.21.5.8WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC3returns a null pointer. If such a character is found, it is the start of the first token.4The strtok function then searches from there for a character that is contained in thecurrent separator string. If no such character is found, the current token extends to theend of the string pointed to by s1, and subsequent searches for a token will return a nullpointer. If such a character is found, it is overwritten by a null character, whichterminates the current token.