亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? library_5.html

?? Glibc的中文手冊
?? HTML
?? 第 1 頁 / 共 3 頁
字號:
<!-- This HTML file has been created by texi2html 1.27
     from library.texinfo on 3 March 1994 -->

<TITLE>The GNU C Library - String and Array Utilities</TITLE>
<P>Go to the <A HREF="library_4.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_4.html">previous</A>, <A HREF="library_6.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_6.html">next</A> section.<P>
<H1><A NAME="SEC57" HREF="library_toc.html#SEC57" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC57">String and Array Utilities</A></H1>
<P>
Operations on strings (or arrays of characters) are an important part of
many programs.  The GNU C library provides an extensive set of string
utility functions, including functions for copying, concatenating,
comparing, and searching strings.  Many of these functions can also
operate on arbitrary regions of storage; for example, the <CODE>memcpy</CODE>
function can be used to copy the contents of any kind of array.  
<P>
It's fairly common for beginning C programmers to "reinvent the wheel"
by duplicating this functionality in their own code, but it pays to
become familiar with the library functions and to make use of them,
since this offers benefits in maintenance, efficiency, and portability.
<P>
For instance, you could easily compare one string to another in two
lines of C code, but if you use the built-in <CODE>strcmp</CODE> function,
you're less likely to make a mistake.  And, since these library
functions are typically highly optimized, your program may run faster
too.
<P>
<A NAME="IDX267"></A>
<H2><A NAME="SEC58" HREF="library_toc.html#SEC58" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC58">Representation of Strings</A></H2>
<P>
This section is a quick summary of string concepts for beginning C
programmers.  It describes how character strings are represented in C
and some common pitfalls.  If you are already familiar with this
material, you can skip this section.
<A NAME="IDX268"></A>
<A NAME="IDX269"></A>
<P>
A <DFN>string</DFN> is an array of <CODE>char</CODE> objects.  But string-valued
variables are usually declared to be pointers of type <CODE>char *</CODE>.
Such variables do not include space for the text of a string; that has
to be stored somewhere else--in an array variable, a string constant,
or dynamically allocated memory (see section <A HREF="library_3.html#SEC18" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_3.html#SEC18">Memory Allocation</A>).  It's up to
you to store the address of the chosen memory space into the pointer
variable.  Alternatively you can store a <DFN>null pointer</DFN> in the
pointer variable.  The null pointer does not point anywhere, so
attempting to reference the string it points to gets an error.
<P>
By convention, a <DFN>null character</DFN>, <CODE>'\0'</CODE>, marks the end of a
string.  For example, in testing to see whether the <CODE>char *</CODE>
variable <VAR>p</VAR> points to a null character marking the end of a string,
you can write <CODE>!*<VAR>p</VAR></CODE> or <CODE>*<VAR>p</VAR> == '\0'</CODE>.
<P>
A null character is quite different conceptually from a null pointer,
although both are represented by the integer <CODE>0</CODE>.
<A NAME="IDX270"></A>
<P>
<DFN>String literals</DFN> appear in C program source as strings of
characters between double-quote characters (<SAMP>`"'</SAMP>).  In ANSI C,
string literals can also be formed by <DFN>string concatenation</DFN>:
<CODE>"a" "b"</CODE> is the same as <CODE>"ab"</CODE>.  Modification of string
literals is not allowed by the GNU C compiler, because literals
are placed in read-only storage.
<P>
Character arrays that are declared <CODE>const</CODE> cannot be modified
either.  It's generally good style to declare non-modifiable string
pointers to be of type <CODE>const char *</CODE>, since this often allows the
C compiler to detect accidental modifications as well as providing some
amount of documentation about what your program intends to do with the
string.
<P>
The amount of memory allocated for the character array may extend past
the null character that normally marks the end of the string.  In this
document, the term <DFN>allocation size</DFN> is always used to refer to the
total amount of memory allocated for the string, while the term
<DFN>length</DFN> refers to the number of characters up to (but not
including) the terminating null character.
<A NAME="IDX272"></A>
<A NAME="IDX273"></A>
<A NAME="IDX274"></A>
<A NAME="IDX275"></A>
<A NAME="IDX271"></A>
<P>
A notorious source of program bugs is trying to put more characters in a
string than fit in its allocated size.  When writing code that extends
strings or moves characters into a pre-allocated array, you should be
very careful to keep track of the length of the text and make explicit
checks for overflowing the array.  Many of the library functions
<EM>do not</EM> do this for you!  Remember also that you need to allocate
an extra byte to hold the null character that marks the end of the
string.
<P>
<H2><A NAME="SEC59" HREF="library_toc.html#SEC59" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC59">String/Array Conventions</A></H2>
<P>
This chapter describes both functions that work on arbitrary arrays or
blocks of memory, and functions that are specific to null-terminated
arrays of characters.
<P>
Functions that operate on arbitrary blocks of memory have names
beginning with <SAMP>`mem'</SAMP> (such as <CODE>memcpy</CODE>) and invariably take an
argument which specifies the size (in bytes) of the block of memory to
operate on.  The array arguments and return values for these functions
have type <CODE>void *</CODE>, and as a matter of style, the elements of these
arrays are referred to as "bytes".  You can pass any kind of pointer
to these functions, and the <CODE>sizeof</CODE> operator is useful in
computing the value for the size argument.
<P>
In contrast, functions that operate specifically on strings have names
beginning with <SAMP>`str'</SAMP> (such as <CODE>strcpy</CODE>) and look for a null
character to terminate the string instead of requiring an explicit size
argument to be passed.  (Some of these functions accept a specified
maximum length, but they also check for premature termination with a
null character.)  The array arguments and return values for these
functions have type <CODE>char *</CODE>, and the array elements are referred
to as "characters".
<P>
In many cases, there are both <SAMP>`mem'</SAMP> and <SAMP>`str'</SAMP> versions of a
function.  The one that is more appropriate to use depends on the exact
situation.  When your program is manipulating arbitrary arrays or blocks of
storage, then you should always use the <SAMP>`mem'</SAMP> functions.  On the
other hand, when you are manipulating null-terminated strings it is
usually more convenient to use the <SAMP>`str'</SAMP> functions, unless you
already know the length of the string in advance.
<P>
<H2><A NAME="SEC60" HREF="library_toc.html#SEC60" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC60">String Length</A></H2>
<P>
You can get the length of a string using the <CODE>strlen</CODE> function.
This function is declared in the header file <TT>`string.h'</TT>.
<A NAME="IDX276"></A>
<P>
<A NAME="IDX277"></A>
<U>Function:</U> size_t <B>strlen</B> <I>(const char *<VAR>s</VAR>)</I><P>
The <CODE>strlen</CODE> function returns the length of the null-terminated
string <VAR>s</VAR>.  (In other words, it returns the offset of the terminating
null character within the array.)
<P>
For example,
<PRE>
strlen ("hello, world")
    => 12
</PRE>
<P>
When applied to a character array, the <CODE>strlen</CODE> function returns
the length of the string stored there, not its allocation size.  You can
get the allocation size of the character array that holds a string using
the <CODE>sizeof</CODE> operator:
<P>
<PRE>
char string[32] = "hello, world"; 
sizeof (string)
    => 32
strlen (string)
    => 12
</PRE>
<P>
<H2><A NAME="SEC61" HREF="library_toc.html#SEC61" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC61">Copying and Concatenation</A></H2>
<P>
You can use the functions described in this section to copy the contents
of strings and arrays, or to append the contents of one string to
another.  These functions are declared in the header file
<TT>`string.h'</TT>.
<A NAME="IDX279"></A>
<A NAME="IDX280"></A>
<A NAME="IDX281"></A>
<A NAME="IDX282"></A>
<A NAME="IDX283"></A>
<A NAME="IDX278"></A>
<P>
A helpful way to remember the ordering of the arguments to the functions
in this section is that it corresponds to an assignment expression, with
the destination array specified to the left of the source array.  All
of these functions return the address of the destination array.
<P>
Most of these functions do not work properly if the source and
destination arrays overlap.  For example, if the beginning of the
destination array overlaps the end of the source array, the original
contents of that part of the source array may get overwritten before it
is copied.  Even worse, in the case of the string functions, the null
character marking the end of the string may be lost, and the copy
function might get stuck in a loop trashing all the memory allocated to
your program.
<P>
All functions that have problems copying between overlapping arrays are
explicitly identified in this manual.  In addition to functions in this
section, there are a few others like <CODE>sprintf</CODE> (see section <A HREF="library_11.html#SEC135" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_11.html#SEC135">Formatted Output Functions</A>) and <CODE>scanf</CODE> (see section <A HREF="library_11.html#SEC153" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_11.html#SEC153">Formatted Input Functions</A>).
<P>
<A NAME="IDX284"></A>
<U>Function:</U> void * <B>memcpy</B> <I>(void *<VAR>to</VAR>, const void *<VAR>from</VAR>, size_t <VAR>size</VAR>)</I><P>
The <CODE>memcpy</CODE> function copies <VAR>size</VAR> bytes from the object
beginning at <VAR>from</VAR> into the object beginning at <VAR>to</VAR>.  The
behavior of this function is undefined if the two arrays <VAR>to</VAR> and
<VAR>from</VAR> overlap; use <CODE>memmove</CODE> instead if overlapping is possible.
<P>
The value returned by <CODE>memcpy</CODE> is the value of <VAR>to</VAR>.
<P>
Here is an example of how you might use <CODE>memcpy</CODE> to copy the
contents of a <CODE>struct</CODE>:
<P>
<PRE>
struct foo *old, *new;
...
memcpy (new, old, sizeof(struct foo));
</PRE>
<P>
<A NAME="IDX285"></A>
<U>Function:</U> void * <B>memmove</B> <I>(void *<VAR>to</VAR>, const void *<VAR>from</VAR>, size_t <VAR>size</VAR>)</I><P>
<CODE>memmove</CODE> copies the <VAR>size</VAR> bytes at <VAR>from</VAR> into the
<VAR>size</VAR> bytes at <VAR>to</VAR>, even if those two blocks of space
overlap.  In the case of overlap, <CODE>memmove</CODE> is careful to copy the
original values of the bytes in the block at <VAR>from</VAR>, including those
bytes which also belong to the block at <VAR>to</VAR>.
<P>
<A NAME="IDX286"></A>
<U>Function:</U> void * <B>memccpy</B> <I>(void *<VAR>to</VAR>, const void *<VAR>from</VAR>, int <VAR>c</VAR>, size_t <VAR>size</VAR>)</I><P>
This function copies no more than <VAR>size</VAR> bytes from <VAR>from</VAR> to
<VAR>to</VAR>, stopping if a byte matching <VAR>c</VAR> is found.  The return
value is a pointer into <VAR>to</VAR> one byte past where <VAR>c</VAR> was copied,
or a null pointer if no byte matching <VAR>c</VAR> appeared in the first
<VAR>size</VAR> bytes of <VAR>from</VAR>.
<P>
<A NAME="IDX287"></A>
<U>Function:</U> void * <B>memset</B> <I>(void *<VAR>block</VAR>, int <VAR>c</VAR>, size_t <VAR>size</VAR>)</I><P>
This function copies the value of <VAR>c</VAR> (converted to an
<CODE>unsigned char</CODE>) into each of the first <VAR>size</VAR> bytes of the
object beginning at <VAR>block</VAR>.  It returns the value of <VAR>block</VAR>.
<P>
<A NAME="IDX288"></A>
<U>Function:</U> char * <B>strcpy</B> <I>(char *<VAR>to</VAR>, const char *<VAR>from</VAR>)</I><P>
This copies characters from the string <VAR>from</VAR> (up to and including
the terminating null character) into the string <VAR>to</VAR>.  Like
<CODE>memcpy</CODE>, this function has undefined results if the strings
overlap.  The return value is the value of <VAR>to</VAR>.
<P>
<A NAME="IDX289"></A>
<U>Function:</U> char * <B>strncpy</B> <I>(char *<VAR>to</VAR>, const char *<VAR>from</VAR>, size_t <VAR>size</VAR>)</I><P>
This function is similar to <CODE>strcpy</CODE> but always copies exactly
<VAR>size</VAR> characters into <VAR>to</VAR>.
<P>
If the length of <VAR>from</VAR> is more than <VAR>size</VAR>, then <CODE>strncpy</CODE>
copies just the first <VAR>size</VAR> characters.
<P>
If the length of <VAR>from</VAR> is less than <VAR>size</VAR>, then <CODE>strncpy</CODE>
copies all of <VAR>from</VAR>, followed by enough null characters to add up
to <VAR>size</VAR> characters in all.  This behavior is rarely useful, but it
is specified by the ANSI C standard.
<P>
The behavior of <CODE>strncpy</CODE> is undefined if the strings overlap.
<P>
Using <CODE>strncpy</CODE> as opposed to <CODE>strcpy</CODE> is a way to avoid bugs
relating to writing past the end of the allocated space for <VAR>to</VAR>.
However, it can also make your program much slower in one common case:
copying a string which is probably small into a potentially large buffer.
In this case, <VAR>size</VAR> may be large, and when it is, <CODE>strncpy</CODE> will
waste a considerable amount of time copying null characters.
<P>
<A NAME="IDX290"></A>
<U>Function:</U> char * <B>strdup</B> <I>(const char *<VAR>s</VAR>)</I><P>
This function copies the null-terminated string <VAR>s</VAR> into a newly
allocated string.  The string is allocated using <CODE>malloc</CODE>; see
section <A HREF="library_3.html#SEC21" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_3.html#SEC21">Unconstrained Allocation</A>.  If <CODE>malloc</CODE> cannot allocate space
for the new string, <CODE>strdup</CODE> returns a null pointer.  Otherwise it
returns a pointer to the new string.
<P>
<A NAME="IDX291"></A>
<U>Function:</U> char * <B>stpcpy</B> <I>(char *<VAR>to</VAR>, const char *<VAR>from</VAR>)</I><P>
This function is like <CODE>strcpy</CODE>, except that it returns a pointer to
the end of the string <VAR>to</VAR> (that is, the address of the terminating
null character) rather than the beginning.
<P>
For example, this program uses <CODE>stpcpy</CODE> to concatenate <SAMP>`foo'</SAMP>
and <SAMP>`bar'</SAMP> to produce <SAMP>`foobar'</SAMP>, which it then prints.
<P>
<PRE>
#include &#60;string.h&#62;

int
main (void)
{
  char *to = buffer;
  to = stpcpy (to, "foo");
  to = stpcpy (to, "bar");
  printf ("%s\n", buffer);
}
</PRE>
<P>
This function is not part of the ANSI or POSIX standards, and is not
customary on Unix systems, but we did not invent it either.  Perhaps it
comes from MS-DOG.
<P>
Its behavior is undefined if the strings overlap.
<P>
<A NAME="IDX292"></A>
<U>Function:</U> char * <B>strcat</B> <I>(char *<VAR>to</VAR>, const char *<VAR>from</VAR>)</I><P>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲欧美日韩国产综合在线| 国产精品一区二区三区99| 国产精品护士白丝一区av| 精品美女在线观看| 欧美成人女星排行榜| 欧美一级久久久| 日韩亚洲欧美成人一区| 91精品国产一区二区三区| 91精品在线免费观看| 欧美日韩高清一区二区三区| 欧美视频完全免费看| 在线观看欧美日本| 欧美在线三级电影| 欧美老肥妇做.爰bbww视频| 欧美亚洲自拍偷拍| 欧美精品高清视频| 日韩亚洲欧美在线| 久久青草欧美一区二区三区| 国产日韩欧美高清| 中文字幕一区二区三区四区 | 精品久久久久久久久久久久久久久| 欧美精品丝袜中出| 日韩欧美成人一区二区| 久久精品视频一区二区| 亚洲国产精品精华液ab| 亚洲黄网站在线观看| 亚洲国产精品一区二区尤物区| 性做久久久久久免费观看欧美| 麻豆传媒一区二区三区| 国产精品一区二区黑丝| 99精品国产91久久久久久| 欧美日韩综合色| 久久网这里都是精品| 亚洲欧美视频在线观看视频| 成人美女视频在线观看| 在线视频欧美区| 精品国产三级a在线观看| 中文字幕日韩一区二区| 天天射综合影视| 国产精品亚洲一区二区三区妖精| 91毛片在线观看| 欧美一区二区三区四区视频| 国产女主播视频一区二区| 一区二区三区成人| 久久91精品国产91久久小草| 99热精品国产| 91精品国产欧美日韩| 国产精品免费av| 日本亚洲最大的色成网站www| 国产高清成人在线| 欧美日韩国产一区| 国产亚洲一二三区| 亚洲成av人影院在线观看网| 国产成人在线观看免费网站| 欧美体内she精高潮| 久久久久久久综合日本| 亚洲高清免费观看| 国产成人午夜电影网| 欧美欧美欧美欧美首页| 欧美国产国产综合| 九一久久久久久| 欧美亚洲自拍偷拍| 国产精品天天看| 蜜臀av性久久久久蜜臀aⅴ | 欧美日韩免费电影| 国产日韩欧美精品一区| 日本成人在线看| 在线国产亚洲欧美| 国产免费成人在线视频| 琪琪久久久久日韩精品| 欧美综合亚洲图片综合区| 中文字幕免费观看一区| 人人爽香蕉精品| 欧美吻胸吃奶大尺度电影 | 国产精品麻豆久久久| 极品美女销魂一区二区三区| 欧美亚男人的天堂| 国产精品乱码人人做人人爱| 精品无码三级在线观看视频| 精品婷婷伊人一区三区三| 国产精品美女久久久久久久久| 黄色精品一二区| 91精品国产一区二区三区| 亚洲色图.com| 97久久超碰国产精品| 国产亚洲精品超碰| 精品一区二区三区香蕉蜜桃| 在线不卡一区二区| 亚洲电影第三页| 欧洲精品在线观看| 亚洲男人的天堂av| 99久久精品国产导航| 亚洲国产精品黑人久久久| 国产一区日韩二区欧美三区| 欧美大黄免费观看| 99久久综合色| 国产精品初高中害羞小美女文| 国产91精品一区二区麻豆网站| 久久久久久黄色| 国产精品综合久久| 久久久国产一区二区三区四区小说 | 另类人妖一区二区av| 欧美日本韩国一区| 亚洲成人在线免费| 777精品伊人久久久久大香线蕉| 亚洲午夜一区二区| 欧美日韩中字一区| 日韩不卡在线观看日韩不卡视频| 欧美精品久久一区| 日韩不卡一二三区| 日韩欧美在线影院| 国精产品一区一区三区mba桃花| 日韩欧美在线观看一区二区三区| 麻豆精品视频在线观看视频| 日韩三级免费观看| 狠狠色丁香婷婷综合| 久久一二三国产| jiyouzz国产精品久久| 亚洲视频在线一区| 欧美日韩亚洲丝袜制服| 肉色丝袜一区二区| 日韩一二三四区| 国产精品一区专区| 国产精品成人免费在线| 色妹子一区二区| 亚洲va欧美va人人爽午夜| 欧美一级二级三级蜜桃| 国产精品一区二区免费不卡| 亚洲视频综合在线| 在线不卡欧美精品一区二区三区| 精品一区二区三区在线观看国产| 国产欧美日韩中文久久| 一本一道久久a久久精品综合蜜臀| 亚洲成人免费在线| xnxx国产精品| 91视频观看免费| 丝袜美腿亚洲一区| 久久久久久久久免费| 色综合久久中文字幕| 七七婷婷婷婷精品国产| 亚洲国产成人一区二区三区| 色吧成人激情小说| 看电视剧不卡顿的网站| 国产精品国产三级国产aⅴ中文| 欧美性色欧美a在线播放| 日韩av不卡一区二区| 国产日韩精品一区| 欧美日韩一区三区| 国产精品一区在线观看乱码| 一区二区三区在线高清| 日韩欧美国产成人一区二区| 成人动漫av在线| 蜜桃精品在线观看| 亚洲色图自拍偷拍美腿丝袜制服诱惑麻豆| 欧美视频一区二区| 成人免费看视频| 99re热视频精品| 国产真实乱对白精彩久久| 亚洲黄网站在线观看| 久久久久亚洲综合| 欧美福利一区二区| 99久久伊人久久99| 麻豆传媒一区二区三区| 亚洲精品成a人| 国产视频一区不卡| 欧美精品v国产精品v日韩精品| 国产精品一二二区| 日本不卡不码高清免费观看| 成人欧美一区二区三区小说| 精品久久久久香蕉网| 欧美体内she精高潮| 99久久久国产精品| 韩国av一区二区| 日本午夜一区二区| 一区二区三区不卡视频| 国产精品色呦呦| 久久蜜桃av一区二区天堂| 欧美高清视频一二三区| 在线一区二区三区四区五区| 福利一区在线观看| 久久精品久久99精品久久| 亚洲一区二区三区美女| 国产精品久久免费看| 久久久亚洲欧洲日产国码αv| 欧美一区午夜视频在线观看| 91国偷自产一区二区使用方法| 成人av在线网| 国产精品一区久久久久| 久久99久久久久| 日韩国产欧美在线观看| 亚洲午夜久久久久久久久久久 | 久久人人97超碰com| 欧美一卡在线观看| 精品视频一区二区不卡| 欧美综合亚洲图片综合区| 色综合久久综合中文综合网| 波多野结衣中文字幕一区| 成人在线综合网| 国产高清不卡二三区| 国产乱码一区二区三区|