📄 string.htm
字号:
<title>The string Library Functions</title><h1 align=center>The string Library Functions</h1><!--INDEX cc2str getword str_fmt str2cc strbalp strbequ --><!--INDEX strcat strccat strchr strcmp strcpy strcspn strdchr --><!--INDEX strdup strempty strequ strichr striequ stristr strlen --><!--INDEX strmerge strncat strncmp strncpy strnwrd strpat --><!--INDEX strpbrk strposn strrchr strrpset strrrot strrset --><!--INDEX strset strsort strspn strstr strtok strtoupper --><!--INDEX toupper --></dl><h2>NAME</h2><dl><dd> cc2str, getword, str_fmt, str2cc, strbalp, strbequ, strcat, strccat, strchr, strcmp, strcpy, strcspn, strdchr, strdup, strempty, strequ, strichr, striequ, stristr, strlen, strmerge, strncat, strncmp, strncpy, strnwrd, strpat, strpbrk, strposn, strrchr, strrpset, strrrot, strrset, strset, strsort, strspn, strstr, strtok, strtoupper, strrpstr, and toupper.<p></dl><h2>SYNOPSIS</h2><dl><dd><pre>#include <string.h>char *<a href="../../lib/cc2str.c">cc2str</a> (char *p, char c)char *<a href="../../lib/getword.c">getword</a> (char *dst, char *p)<a href="../../lib/str_fmt.c">str_fmt</a> (char *p, int size,char *fmt)int <a href="../../lib/str2cc.c">str2cc</a> (char *p)char *<a href="../../lib/strbalp.c">strbalp</a> (char *p)int <a href="../../lib/strbequ.c">strbequ</a> (char *s1, char *s2)char *<a href="../../lib/strcat.c">strcat</a> (char *dst, char *src)char *<a href="../../lib/strccat.c">strccat</a> (char *dst, char c)char *<a href="../../lib/strchr.c">strchr</a> (char *p, char c)int <a href="../../lib/strcmp.s">strcmp</a> (char *s1, char *s2)char *<a href="../../lib/strcpy.s">strcpy</a> (char *dst, char *src)int <a href="../../lib/strcspn.c">strcspn</a> (char *p, char *s)char *<a href="../../lib/strdchr.c">strdchr</a> (const char *p)char *<a href="../../lib/strdup.c">strdup</a> (const char *s)int <a href="../../lib/strempty.c">strempty</a> (const char *p)int <a href="../../lib/strequ.c">strequ</a> (const char *s1, const char *s2)char *<a href="../../lib/strichr.c">strichr</a> (const char *p, const char c)int <a href="../../lib/striequ.c">striequ</a> (const char *s1, const char *s2)<a href="../../lib/stristr.c">stristr</a> (const char *dst, const char *p)int <a href="../../lib/strlen.c">strlen</a> (char *p)void <a href="../../lib/strmerge.c">strmerge</a> (char *d, char *s)char *<a href="../../lib/strncat.c">strncat</a> (char *dst, char *src, int n)int <a href="../../lib/strncmp.c">strncmp</a> (const char *s1, const char *s2, int n)char *<a href="../../lib/strncpy.c">strncpy</a> (char *dst, char *src, int n)int <a href="../../lib/strnwrd.c">strnwrd</a> (char *p)int <a href="../../lib/strpat.c">strpat</a> (char *p, char *pat)char *<a href="../../lib/strpbrk.c">strpbrk</a> (char *s1, char *s2)char *<a href="../../lib/strposn.c">strposn</a> (char *p, char *q)char *<a href="../../lib/strrchr.c">strrchr</a> (const char *p, char c)char *<a href="../../lib/strrpset.c">strrpset</a> (char *p, char *set)char *<a href="../../lib/strrpstr.c">strrpstr</a> (char *p, char *pat)char *<a href="../../lib/strrrot.c">strrrot</a> (char *p)char *<a href="../../lib/strrset.c">strrset</a> (char *p, char *set)char *<a href="../../lib/strset.c">strset</a> (char *p, char *set)void <a href="../../lib/strsort.c">strsort</a> (char *p)size_t <a href="../../lib/strspn.c">strspn</a> (const char *s1, const char *s2)char *<a href="../../lib/strstr.c">strstr</a> (const char *s1, const char *s2)char *<a href="../../lib/strtok.c">strtok</a> (char *s1, const char *s2)char *<a href="../../lib/strtoupp.c">strtoupper</a> (char *p)int <a href="../../lib/toupper.c">toupper</a> (int c)</pre> where:<p> <table><tr><td> c </td><td>is a character. </td></tr><tr><td> dst </td><td>is the destination string. </td></tr><tr><td> fmt </td><td>is a format to apply to the string. </td></tr><tr><td> n </td><td>is an integer indicating the number of characters to concatenate or copy. </td></tr><tr><td> p </td><td>is a pointer to a string. </td></tr><tr><td> pat </td><td>is a sequence of string characters used in search and replace operations. </td></tr><tr><td> q </td><td>is a pointer to a location in the string pointed to by p. </td></tr><tr><td> s1 </td><td>is the first string in comparison operations. </td></tr><tr><td> s2 </td><td>is the second string in comparison operations. </td></tr><tr><td> set </td><td>is a character to which all characters are set in string p by strset. </td></tr><tr><td> size </td><td>is the string size. </td></tr><tr><td> src </td><td>is the source string. </td></tr></table><p> Note that strmerge and strsort do not explicitly declare void returns and may generate compiler warnings if the programmer uses void return declarations for them.<p></dl><h2>Functional Description</h2><dl><dd> These functions have the same functions as the C library function of the same name, with the exception of the strncpy routine, which always terminates the resulting string with a null character.<p> The following #define declarations are the possible values for the fmt argument in the str_fmt function.<p> <table><tr><td> #define FMT_RJUST 0 </td><td>Right justifies the string. </td></tr><tr><td> #define FMT_LJUST 1 </td><td>Left justifies the string. </td></tr><tr><td> #define FMT_RJUST0 2 </td><td>Right justifies the string and fills null spaces in the string with zeros. </td></tr><tr><td> #define FMT_CENTER 3 </td><td>Centers the string. </td></tr></table><p> The following list shows the operations that the string functions perform. The string functions are in alphabetical order.<p> <table><tr><td> cc2str </td><td>converts a control character to a string and returns the result in the string p. </td></tr><tr><td> getword </td><td>copies the next word from the string p into dst, or else returns zero if not found. </td></tr><tr><td> str_fmt </td><td>formats the string p in a field size and format fmt. </td></tr><tr><td> str2cc </td><td>converts the string p into a control character. </td></tr><tr><td> strbalp </td><td>returns a pointer to a balancing parenthesis in a string p. </td></tr><tr><td> strbequ </td><td>returns one if s2 matches first part of s1. </td></tr><tr><td> strcat </td><td>concatenates string src to string dst. </td></tr><tr><td> strccat </td><td>concatenates character char to string dst. </td></tr><tr><td> strchr </td><td>returns a pointer to the character c in the string p, or else returns NULL if the character c is not found. </td></tr><tr><td> strcmp </td><td>returns "+1" if string s1 is more than string s2, "-1" if string s2 is more than s1, or "0" if string s1 is equivalent to string s2. </td></tr><tr><td> strcpy </td><td>copies string src to string dst. </td></tr><tr><td> strcspn </td><td>returns the number of consecutive characters in string p that are not in string s. </td></tr><tr><td> strdchr </td><td>deletes the first character in the string p. </td></tr><tr><td> strdup </td><td>returns a pointer to a duplicate copy of string. </td></tr><tr><td> strempty </td><td>returns one if the string p contains nothing but isspace. </td></tr><tr><td> strequ </td><td>returns one if string s1 matches string s2, else returns zero if not found. Case is not ignored. </td></tr><tr><td> strichr </td><td>inserts character c as the first character in the string p. </td></tr><tr><td> striequ </td><td>returns one if string s1 matches string s2, else returns zero if not found. Case is ignored. </td></tr><tr><td> stristr </td><td>inserts the string p at the beginning of string dst. </td></tr><tr><td> strlen </td><td>returns the length of the string p. </td></tr><tr><td> strmerge </td><td>inserts characters from string s into blank spaces in string d unless string s contains blank characters. </td></tr><tr><td> strncat </td><td>concatenates n characters from string src to string dst. </td></tr><tr><td> strncmp </td><td>makes an unsigned comparison between a specific number of characters in two strings. </td></tr><tr><td> strncpy </td><td>copies n characters from string src to string dst. </td></tr><tr><td> strnwrd </td><td>returns a count of the words in the string p. </td></tr><tr><td> strpat </td><td>returns one if pat matches the string p, else returns zero. The strpat function supports the wildcards ? and *. </td></tr><tr><td> strpbrk </td><td>returns a pointer to the first character in string s2, which is within string s1. </td></tr><tr><td> strposn </td><td>returns a pointer to q in the string p, else returns zero if not found. </td></tr><tr><td> strrchr </td><td>returns a pointer to the last character in string p. </td></tr><tr><td> strrpset </td><td>returns a pointer to the last character in a set of characters within a string, ignoring inner parentheses. </td></tr><tr><td> strrpstr </td><td>like strrpset except that it looks for a single value. </td></tr><tr><td> strrrot </td><td>rotates all characters in string p one character to the right and returns a pointer to the last character in the string. </td></tr><tr><td> strrset </td><td>returns a pointer to the last character in the set of characters within string p. </td></tr><tr><td> strset </td><td>returns a pointer to the first character from SET in the string p. </td></tr><tr><td> strsort </td><td>sorts characters in string p in numeric order. </td></tr><tr><td> strspn </td><td>returns the number of characters in the first consecutive string of characters in s1 that consist entirely of characters in s2. </td></tr><tr><td> strstr </td><td>returns a pointer to the element in s1 where the substring s2 begins. </td></tr><tr><td> strtok </td><td>defines a string as a series of tokens separated by spans of one or more characters of type s2, and returns a pointer to the next token in s1. </td></tr><tr><td> strtoupper </td><td>converts the string p to upper case. </td></tr><tr><td> toupper </td><td>translates c to upper case. </td></tr></table></dl><p><hr><b>Navigation:</b> <a href="../index.htm">Document Home</a> | <a href="../doctoc.htm">Document Contents</a> | <a href="../docindex.htm">Document Index</a> <p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -