📄 string.html
字号:
<CODE>s2</CODE>, using a comparison rule that depends on the current<A HREF="locale.html#locale">locale</A>. If <CODE>s1</CODE>compares greater than <CODE>s2</CODE> by this rule, the function returns apositive number. If the two strings compare equal,it returns zero. Otherwise, it returns a negative number.</P><H2><A NAME="strcpy"><CODE>strcpy</CODE></A></H2><PRE>char *<B>strcpy</B>(char *s1, const char *s2);</PRE><P>The function copies the string <CODE>s2</CODE>, including itsterminating null character, to successive elementsof the array of <I>char</I>whose first element has the address <CODE>s1</CODE>. It returns<CODE>s1</CODE>.</P><H2><A NAME="strcspn"><CODE>strcspn</CODE></A></H2><PRE>size_t <B>strcspn</B>(const char *s1, const char *s2);</PRE><P>The function searches for the first element<CODE>s1[i]</CODE> in the string <CODE>s1</CODE> thatequals <I>any one</I> of the elements of the string <CODE>s2</CODE> andreturns <CODE>i</CODE>. Each terminating null characteris considered part of its string.</P><H2><A NAME="strerror"><CODE>strerror</CODE></A></H2><PRE>char *<B>strerror</B>(int errcode);</PRE><P>The function returns a pointer to an internal static-duration objectcontaining the message string corresponding to the error code<CODE>errcode</CODE>. The program must not alter any of the values stored inthis object. A later call to <CODE>strerror</CODE> can alter the value storedin this object.</P><H2><A NAME="strlen"><CODE>strlen</CODE></A></H2><PRE>size_t <B>strlen</B>(const char *s);</PRE><P>The function returns the number of characters in the string<CODE>s</CODE>, <I>not</I> including its terminating null character.</P><H2><A NAME="strncat"><CODE>strncat</CODE></A></H2><PRE>char *<B>strncat</B>(char *s1, const char *s2, size_t n);</PRE><P>The function copies the string <CODE>s2</CODE>, <I>not</I> includingits terminating null character, to successive elements of the array of<I>char</I> that stores the string <CODE>s1</CODE>, beginning with theelement that stores the terminating null character of <CODE>s1</CODE>. Thefunction copies no more than <CODE>n</CODE> characters from<CODE>s2</CODE>. It then stores a null character, in the next element to bealtered in <CODE>s1</CODE>, and returns <CODE>s1</CODE>.</P><H2><A NAME="strncmp"><CODE>strncmp</CODE></A></H2><PRE>int <B>strncmp</B>(const char *s1, const char *s2, size_t n);</PRE><P>The function compares successive elements from two strings,<CODE>s1</CODE> and <CODE>s2</CODE>, until it finds elements that are notequal or until it has compared the first <CODE>n</CODE> elements of the twostrings.</P><UL><LI>If all elements are equal, the function returns zero.<LI>If the differing element from <CODE>s1</CODE> is greater than theelement from <CODE>s2</CODE> (both taken as <I>unsigned char</I>), thefunction returns a positive number.<LI>Otherwise, it returns a negative number.</UL><H2><A NAME="strncpy"><CODE>strncpy</CODE></A></H2><PRE>char *<B>strncpy</B>(char *s1, const char *s2, size_t n);</PRE><P>The function copies the string <CODE>s2</CODE>, <I>not</I> includingits terminating null character, to successive elements of the array of<I>char</I> whose first element has the address <CODE>s1</CODE>. It copies nomore than <CODE>n</CODE> characters from <CODE>s2</CODE>. The function thenstores zero or more null characters in the next elements to be altered in<CODE>s1</CODE> until it stores a total of <CODE>n</CODE> characters. Itreturns <CODE>s1</CODE>.</P><H2><A NAME="strpbrk"><CODE>strpbrk</CODE></A></H2><PRE>char *<B>strpbrk</B>(const char *s1, const char *s2); <B>[not in C++]</B>const char *<B>strpbrk</B>(const char *s1, const char *s2); <B>[C++ only]</B>char *<B>strpbrk</B>(char *s1, const char *s2); <B>[C++ only]</B></PRE><P>The function searches for the first element<CODE>s1[i]</CODE> in the string <CODE>s1</CODE> thatequals <I>any one</I> of the elements of the string <CODE>s2</CODE>. Itconsiders each terminating null character as part of its string. If<CODE>s1[i]</CODE> is not the terminating null character, thefunction returns <CODE>&s1[i]</CODE>; otherwise, it returns anull pointer.</P><H2><A NAME="strrchr"><CODE>strrchr</CODE></A></H2><PRE>char *<B>strrchr</B>(const char *s, int c); <B>[not in C++]</B>const char *<B>strrchr</B>(const char *s, int c); <B>[C++ only]</B>char *<B>strrchr</B>(char *s, int c); <B>[C++ only]</B></PRE><P>The function searches for the last element of the string <CODE>s</CODE>that equals <CODE>(char)c</CODE>. It considers the terminating null characteras part of the string. If successful, the function returns the address of thematching element; otherwise, it returns a null pointer.</P><H2><A NAME="strspn"><CODE>strspn</CODE></A></H2><PRE>size_t <B>strspn</B>(const char *s1, const char *s2);</PRE><P>The function searches for the first element<CODE>s1[i]</CODE> in the string <CODE>s1</CODE> thatequals <I>none</I> of the elements of the string <CODE>s2</CODE> and returns<CODE>i</CODE>. It considers the terminating null characteras part of the string <CODE>s1</CODE> only.</P><H2><A NAME="strstr"><CODE>strstr</CODE></A></H2><PRE>char *<B>strstr</B>(const char *s1, const char *s2); <B>[not in C++]</B>const char *<B>strstr</B>(const char *s1, const char *s2); <B>[C++ only]</B>char *<B>strstr</B>(char *s1, const char *s2); <B>[C++ only]</B></PRE><P>The function searches for the first sequence of elements in the string<CODE>s1</CODE> that matches the sequence of elements in the string<CODE>s2</CODE>, <I>not</I> including its terminating null character. Ifsuccessful, the function returns the address of the matching first element;otherwise, it returns a null pointer.</P><H2><A NAME="strtok"><CODE>strtok</CODE></A></H2><PRE>char *<B>strtok</B>(char *s1, const char *s2);</PRE><P>If <CODE>s1</CODE> is not a null pointer, the function begins a searchof the string <CODE>s1</CODE>. Otherwise, it begins a search of the stringwhose address was last stored in an internal static-duration object on anearlier call to the function, as described below. The search proceeds asfollows:</P><OL><LI>The function searches the string for <CODE>begin</CODE>,the address of the first element that equals<I>none</I> of the elements of the string<CODE>s2</CODE> (a set of token separators). It considers the terminatingnull character as part of the search string only.<LI>If the search does not find an element, the function stores the addressof the terminating null character in the internal static-duration object (sothat a subsequent search beginning with that address will fail) and returns anull pointer. Otherwise, the function searches from <CODE>begin</CODE> for<CODE>end</CODE>, the address of the first elementthat equals <I>any one</I> of the elements of the string <CODE>s2</CODE>.It again considers the terminatingnull character as part of the search string only.<LI>If the search does not find an element, the function stores the addressof the terminating null character in the internal static-duration object.Otherwise, it stores a null character in the element whose address is<CODE>end</CODE>. Then it stores the addressof the next element after <CODE>end</CODE> inthe internal static-duration object(so that a subsequent search beginning withthat address will continue with the remaining elements of the string) andreturns <CODE>begin</CODE>.</OL><H2><A NAME="strxfrm"><CODE>strxfrm</CODE></A></H2><PRE>size_t <B>strxfrm</B>(char *s1, const char *s2, size_t n);</PRE><P>The function stores a string in the array of <I>char</I> whose firstelement has the address <CODE>s1</CODE>. It stores no more than<CODE>n</CODE> characters, <I>including</I> the terminating null character,and returns the number of characters needed to represent the entire string,<I>not</I> including the terminating null character. If the value returned is<CODE>n</CODE> or greater, the values stored in the array are indeterminate.(If <CODE>n</CODE> is zero, <CODE>s1</CODE> can be a null pointer.)</P><P><CODE>strxfrm</CODE> generates the string it stores from the string<CODE>s2</CODE> by using a transformation rule that depends on the current<A HREF="locale.html#locale">locale</A>.For example, if <CODE>x</CODE> is a transformationof <CODE>s1</CODE> and <CODE>y</CODE> is a transformationof <CODE>s2</CODE>, then<CODE><A HREF="#strcmp">strcmp</A>(x, y)</CODE>returns the same value as<CODE><A HREF="#strcoll">strcoll</A>(s1, s2)</CODE>.</P><HR><P>See also the<B><A HREF="index.html#Table of Contents">Table of Contents</A></B> and the<B><A HREF="_index.html">Index</A></B>.</P><P><I><A HREF="crit_pb.html">Copyright</A> © 1989-2002by P.J. Plauger and Jim Brodie. All rights reserved.</I></P><!--V4.01:1125--></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -