mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-08 15:04:05 +08:00
36 lines
803 B
HTML
36 lines
803 B
HTML
<h1>字符串函数 - strdup</h1>
|
||
|
||
|
||
<p>原型:extern char *strdup(char *s);</p>
|
||
|
||
<p>用法:#include <string.h></p>
|
||
|
||
<p>功能:复制字符串s</p>
|
||
|
||
<p>说明:返回指向被复制的字符串的指针,所需空间由malloc()分配且可以由free()释放。</p>
|
||
|
||
举例:<pre><code class="language-c">
|
||
|
||
|
||
// strdup.c
|
||
|
||
#include <syslib.h>
|
||
#include <string.h>
|
||
|
||
main()
|
||
{
|
||
char *s="Golden Global View";
|
||
char *d;
|
||
|
||
clrscr();
|
||
|
||
d=strdup(s);
|
||
printf("%s",d);
|
||
|
||
getchar();
|
||
return 0;
|
||
}
|
||
|
||
</code></pre>相关函数:<a href="memccpy.html">memccpy</a>,<a href="memcpy.html">memcpy</a>,<a href="strcpy.html">strcpy</a>
|
||
|