Page 1030 DESCRIPTION The strcmp() function compares the two strings s1 and s2. It returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2. The strncmp() function is similar, except it only compares the first n characters of s1. RETURN VALUE The strcmp() and strncmp() functions return an integer less than, equal to, or greater than zero if s1 (or the first n bytes thereof) is found, respectively, to be less than, to match, or be greater than s2. CONFORMS TO SVID 3, POSIX, BSD 4.3, ISO 9899 SEE ALSO bcmp(3), memcmp(3), strcasecmp(3), strncasecmp(3), strcoll(3) 11 April 1993 strcollstrcollCompares two strings using the current locale SYNOPSIS #include <string.h> int strcoll(const char *s1, const char *s2); DESCRIPTION The strcoll() function compares the two strings s1 and s2. It returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2. The comparison is based on strings interpreted as appropriate for the program's current locale for category LC_COLLATE. (See setlocale(3)). RETURN VALUE The strcoll() function returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2, when both are interpreted as appropriate for the current locale. CONFORMS TO SVID 3, BSD 4.3, ISO 9899 NOTES The Linux C Library currently hasn't implemented the complete POSIX-collating. In the POSIX or C locales, strcoll() is equivalent to strcmp(). SEE ALSO bcmp(3), memcmp(3), strcasecmp(3), strcmp(3), strxfrm(3), setlocale(3) GNU, 12 April 1993 strcpy, strncpystrcpy, strncpyCopy a string Page 1031 SYNOPSIS #include <string.h> char *strcpy(char *dest, const char *src); char *strncpy(char *dest, const char *src, size_t n); DESCRIPTION The strcpy() function copies the string pointed to be src (including the terminating \0 character) to the array pointed to by dest. The strings may not overlap, and the destination string dest must be large enough to receive the copy. The strncpy() function is similar, except that not more than n bytes of src are copied. Thus, if there is no null byte among the first n bytes of src, the result will not be null-terminated. In the case where the length of src is less than that of n, the remainder of dest will be padded with nulls. RETURN VALUE The strcpy() and strncpy() functions return a pointer to the destination string dest. CONFORMS TO SVID 3, POSIX, BSD 4.3, ISO 9899 SEE ALSO bcopy(3), memccpy(3), memcpy(3), memmove(3) GNU, 11 April 1993 strdupstrdupDuplicates a string SYNOPSIS #include <string.h> char *strdup(const char *s); DESCRIPTION The strdup() function returns a pointer to a new string that is a duplicate of the string s. Memory for the new string is obtained with malloc(3), and can be freed with free(3). RETURN VALUE The strdup() function returns a pointer to the duplicated string, or NULL if insufficient memory was available. ERRORS
CONFORMS TO SVID 3, BSD 4.3 SEE ALSO calloc(3), malloc(3), realloc(3), free(3) GNU, 12 April 1993 Page 1032 strerrorstrerrorReturns string describing error code SYNOPSIS #include <string.h> char *strerror(int errnum); DESCRIPTION The strerror() function returns a string describing the error code passed in the argument errnum. The string can only be used until the next call to strerror(). RETURN VALUE The strerror() function returns the appropriate description string, or an unknown error message if the error code is unknown. CONFORMS TO SVID 3, POSIX, BSD 4.3, ISO 9899 SEE ALSO errno(3), perror(3), strsignal(3) GNU, 13 April 1993 strfrystrfryRandomizes a string SYNOPSIS #include <string.h> char *strfry(char *string); DESCRIPTION The strfry() function randomizes the contents of string by using rand(3) to randomly swap characters in the string. The result is an anagram of string. RETURN VALUE The strfry() function returns a pointer to the randomized string. CONFORMS TO The strfry() function is unique to the Linux C Library and GNU C Library. SEE ALSO memfrob(3) GNU, 12 April 1993 strftimestrftimeFormats date and time Page 1033 SYNOPSIS #include <time.h> size t strftime(char *s, size_t max, const char *format, const struct tm *tm); DESCRIPTION The strftime() function formats the broken-down time tm according to the format specification format and places the result in the character array s of size max. Ordinary characters placed in the format string are copied to s without conversion. Conversion specifiers are introduced by a % character, and are replaced in s as follows:
The broken-down time structure tm is defined in <time.h> as follows: struct tm { int tm sec; /* seconds */ int tm min; /* minutes */ int tm hour; /* hours */ int tm mday; /* day of the month */ int tm mon; /* month */ int tm year; /* year */ int tm wday; /* day of the week */ int tm yday; /* day in the year */ int tm isdst; /* daylight saving time */ }; Page 1034 The members of the tm structure are
RETURN VALUE The strftime() function returns the number of characters placed in the array s, not including the terminating NULL character. If the value equals max, it means that the array was too small. CONFORMS TO SVID 3, POSIX, BSD 4.3, ISO 9899 SEE ALSO date(1), time(2), ctime(3), setlocale(3), sprintf(3) NOTES The function supports only those locales specified in locale(7) GNU, 2 July 1993
strcasecmp, strcat, strchr, strcmp, strcoll,
strcpy, strcspn,
|
%% | Same as %. |
%a, %A | Day of week, using locale's weekday names; either the abbreviated or full name may be specified. |
%b, %B, %h | Month, using locale's month names; either the abbreviated or full name may be specified. |
%c | Date and time as %x, %X. |
%C | Date and time, in locale's long-format date and time representation. |
%d, %e | Day of month (1_31; leading zeroes are permitted but not required). |
%D | Date as %m/%d/%y. |
%H, %k | Hour (0_23; leading zeroes are permitted but not required). |
%I, %l | Hour (0_12; leading zeroes are permitted but not required). |
%j | Day number of year (001_366). |
%m | Month number (1_12; leading zeroes are permitted but not required). |
%M | Minute (0_59; leading zeroes are permitted but not required). |
%p | Locale's equivalent of a.m. or p.m. |
%r | Time as %I:%M:%S %p. |
Page 1037
%R | Time as %H:%M. |
%S | Seconds (0_61; leading zeroes are permitted but not required; extra second allowed for leap years). |
%T | Time as %H:%M:%S. |
%w | Weekday number (0_6) with Sunday as the first day of the week. |
%x | Date, using locale's date format. |
%X | Time, using locale's time format. |
%y | Year within century (0_99; leading zeroes are permitted but not required. Unfortunately, this makes the assumption that we are stuck in the 20th century, as 1900 is automatically added onto this number for the tm year field.) |
%Y | Year, including century (for example, 1988). |
Case is ignored when matching items such as month or weekday names.
The broken-down time structure tm is defined in <time.h> as follows:
struct tm { int tm_sec; /* seconds */ int tm_min; /* minutes */ int tm_hour; /* hours */ int tm_mday; /* day of the month */ int tm_mon; /* month */ int tm_year; /* year */ int tm_wday; /* day of the week */ int tm_yday; /* day in the year */ int tm_isdst; /* daylight saving time */ };
RETURN VALUE
The strptime() function returns a pointer to the character following the last character in the string pointed to by buf.
SEE ALSO
strftime(3), time(2), setlocale(3), scanf(3)
BUGS
The return values point to static data, whose contents are overwritten by each call.
NOTES
This function is only available in libraries newer than version 4.6.5.
The function supports only those locales specified in locale(7).
GNU, 26 September 1994
strsepExtracts token from string
SYNOPSIS
#include <string.h> char *strsep(char **stringp, const char *delim);
Page 1038
DESCRIPTION
The strsep() function returns the next token from the string stringp which is delimited by delim. The token is terminated with a \0 character and stringp is updated to point past the token.
RETURN VALUE
The strsep() function returns a pointer to the token, or NULL if delim is not found in stringp.
CONFORMS TO
BSD 4.3
SEE ALSO
index(3), memchr(3), rindex(3), strchr(3), strpbrk(3), strspn(3), strstr(3), strtok(3)
GNU, 12 April 1993
strsignalReturns string describing signal
SYNOPSIS
#include <string.h> char *strsignal(int sig); extern const char * const sys_siglist[]
DESCRIPTION
The strsignal() function returns a string describing the signal number passed in the argument sig. The string can only be used until the next call to strsignal().
The array sys_siglist holds the signal description strings indexed by signal number.
RETURN VALUE
The strsignal() function returns the appropriate description string, or an unknown signal message if the signal number is invalid.
SEE ALSO
psignal(3), strerror(3)
GNU, 13 April 1993
strspn, strcspnSearch a string for a set of characters
SYNOPSIS
#include <string.h> size t strspn(const char *s, const char *accept); size t strcspn(const char *s, const char *reject);
DESCRIPTION
The strspn() function calculates the length of the initial segment of s, which consists entirely of characters in accept.
The strcspn() function calculates the length of the initial segment of s, which consists entirely of characters not in reject.