字符串函数strncpy
来源:互联网 发布:大数据软件平台公司 编辑:程序博客网 时间:2024/06/05 17:21
原型:extern char *strncpy(char *dest, char *src, int n);
用法:#include <string.h>
功能:把src所指由NULL结束的字符串的前n个字节复制到dest所指的数组中。
说明:
如果src的前n个字节不含NULL字符,则结果不会以NULL字符结束。
如果src的长度小于n个字节,则以NULL填充dest直到复制完n个字节。
src和dest所指内存区域不可以重叠且dest必须有足够的空间来容纳src的字符串。
返回指向dest的指针。
举例:
// strncpy.c
#include <syslib.h>
#include <string.h>
main()
{
char *s="Golden Global View";
char *d="Hello, GGV Programmers";
char *p=strdup(s);
clrscr();
textmode(0x00); // enable 6 lines mode
strncpy(d,s,strlen(s));
printf("%s/n",d);
strncpy(p,s,strlen(d));
printf("%s",p);
getchar();
return 0;
}
相关函数:memccpy,memcpy,stpcpy,strcpy
(摘自 http://www.ggv.com.cn/forum/clib/string/strstr.html)
用法:#include <string.h>
功能:把src所指由NULL结束的字符串的前n个字节复制到dest所指的数组中。
说明:
如果src的前n个字节不含NULL字符,则结果不会以NULL字符结束。
如果src的长度小于n个字节,则以NULL填充dest直到复制完n个字节。
src和dest所指内存区域不可以重叠且dest必须有足够的空间来容纳src的字符串。
返回指向dest的指针。
举例:
// strncpy.c
#include <syslib.h>
#include <string.h>
main()
{
char *s="Golden Global View";
char *d="Hello, GGV Programmers";
char *p=strdup(s);
clrscr();
textmode(0x00); // enable 6 lines mode
strncpy(d,s,strlen(s));
printf("%s/n",d);
strncpy(p,s,strlen(d));
printf("%s",p);
getchar();
return 0;
}
相关函数:memccpy,memcpy,stpcpy,strcpy
(摘自 http://www.ggv.com.cn/forum/clib/string/strstr.html)
- 字符串函数strncpy
- strncpy字符串拷贝函数
- 字符串处理函数(三):strncpy
- strncpy函数
- strncpy() 函数
- strncpy() 函数
- strncpy函数
- strncpy函数
- 函数 strncpy
- strncpy()函数
- strncpy函数
- strncpy()函数
- strncpy函数
- strncpy()函数
- strncpy函数
- 重写string.h中的字符串操作函数--strncpy
- 字符串 函数sprintf、strcpy 、strncpy及 memcpy , strftime,strcat
- [C/C++] 字符串处理函数 strstr 与 strncpy
- 字符串函数strncat
- 字符串函数strncmp
- 字符串函数strnicmp,strncmpi
- IEEE 1588 Sync和Follow_Up格式
- c#中Hashtable用法简述
- 字符串函数strncpy
- 字符串函数strpbrk
- 电子地图
- 字符串函数strrev
- 字符串函数strset
- 字符串函数strstr
- 字符串函数strtok
- 字符串函数strtok
- 字符串函数strupr