United States-English |
|
|
HP-UX Reference > Sstring(3C)HP-UX 11i Version 3: February 2007 |
|
NAMEstring: strcasecmp(), strcat(), strchr(), strcmp(), strcoll(), strcpy(), strcspn(), strdup(), strlen(), strncasecmp(), strncat(), strncmp(), strncpy(), strpbrk(), strrchr(), strrstr(), strspn(), strstr(), strtok(), strtok_r(), strxfrm(), index(), rindex() — character string operations SYNOPSIS#include <string.h> #include <strings.h> char *strcat(char *__restrict s1, const char *__restrict s2); char *strncat(char *__restrict s1, const char *__restrict s2, size_t n); int strcmp(const char *s1, const char *s2); int strncmp(const char *s1, const char *s2, size_t n); int strcasecmp(const char *s1, const char *s2); int strncasecmp(const char *s1, const char *s2, size_t n); char *strcpy(char *__restrict s1, const char *__restrict s2); char *strncpy(char *__restrict s1, const char *__restrict s2, size_t n); char *strdup(const char *s); size_t strlen(const char *s); char *strchr(const char *s, int c); char *strrchr(const char *s, int c); char *strpbrk(const char *s1, const char *s2); size_t strspn(const char *s1, const char *s2); size_t strcspn(const char *s1, const char *s2); char *strstr(const char *s1, const char *s2); char *strrstr(const char *s1, const char *s2); char *strtok(char *__restrict s1, const char *__restrict s2); char *strtok_r(char *s1, const char *s2, char **last); int strcoll(const char *s1, const char *s2); size_t strxfrm(char *__restrict s1, const char *__restrict s2, size_t n); char *index(const char *s, int c); char *rindex(const char *s, int c); RemarksAll functions except index() and rindex() are declared in both headers, so only one of the two headers needs to be included. The functions index() and rindex() are declared only in <strings.h>. They are provided solely for portability of BSD applications, and are not recommended for new applications where portability is important. For portable applications, use <string.h>, strchr(), and strrchr() instead. DESCRIPTIONArguments s1, s2, and s point to strings (arrays of characters terminated by a null byte). Definitions for all these functions, the type size_t, and the constant NULL are provided in the <string.h> header.
strcoll() has better performance with respect to strxfrm() in cases where a given string is compared to other strings only a few times, or where the strings to be compared are long but a difference in the strings that determines their relative ordering usually comes among the first few characters. strxfrm() offers better performance in, for example, a sorting routine where a number of strings are each transformed just once and the transformed versions are compared against each other many times. EXTERNAL INFLUENCESLocaleThe LC_CTYPE category determines the interpretation of the bytes within the string arguments to the strcoll() and strxfrm() functions as single and/or multibyte characters. It also determines the case conversions to be done for the strcasecmp() and strncasecmp() functions. The LC_COLLATE category determines the collation ordering used by the strcoll() and strxfrm() functions. EXAMPLESThe following sample piece of code finds the tokens, separated by blanks, that are in the string s (assuming that there are at most MAXTOK tokens): int i = 0; char *s, *last, *tok[MAXTOK]; tok[0] = strtok_r(s, " ", &last); while (tok[++i] = strtok_r(NULL, " ", &last)); WARNINGSThe functions strcat(), strncat(), strcpy(), strncpy(), strtok(), and strtok_r() alter the contents of the array to which s1 points. They do not check for overflow of the array. Null pointers for destination strings cause undefined behavior. Character movement is performed differently in different implementations, so moves involving overlapping source and destination strings may yield surprises. The transformed string produced by strxfrm() for a language using an 8-bit code set is usually at least twice as large as the original string and may be as much four times as large (ordinary characters occupy two bytes each in the transformed string, 1-to-2 characters four bytes, 2-to-1 characters two bytes per original pair, and don't-care characters no bytes). Each character of a multibyte code set (Asian languages) occupies three bytes in the transformed string. For functions strcoll() and strxfrm() results are undefined if the languages specified by the LC_COLLATE and LC_CTYPE categories use different code sets. Users of strtok_r() should also note that the prototype of this function will change in the next release for conformance with the new POSIX Threads standard. STANDARDS CONFORMANCEstrcat(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C strchr(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C strcmp(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C strcoll(): AES, SVID3, XPG3, XPG4, ANSI C strcpy(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C strcspn(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C strdup(): SVID2, SVID3 strlen(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C strncat(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C strncmp(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C strncpy(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C strpbrk(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C strrchr(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C strspn(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C strstr(): AES, SVID3, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C strtok(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C strxfrm(): AES, SVID3, XPG3, XPG4, ANSI C |
Printable version | ||
|