当前位置:编程学习 > C/C++ >>

memccpy() -- string字符串的拷贝

 
相关函数: bcopy(), memcpy(), memmove(), strcpy(), strncpy()
表头文件: #include <string.h>
定义函数: void *memccpy(void *dest, const void *src, int c, size_t n);
函数说明: memccpy()用来拷贝src所指的内存内容前n个字节到dest所指的地址上。与memcpy()不同的是,memccpy()如果在src中遇到某个特定值(int c)立即停止复制。
返回值:   返回指向dest中值为c的下一个字节指针。返回值为0表示在src所指内存前n个字节中没有值为c的字节。

void * memccpy (void *restrict to, const void *restrict from, int c, size t [Function]
size)
This function copies no more than size bytes from from to to, stopping if a byte
matching c is found. The return value is a pointer into to one byte past where c was
copied, or a null pointer if no byte matching c appeared in the first size bytes of from.

#include <string.h>
#include <stdio.h>

int main()
{
    char a[] = "string[a]";
    char b[] = "string(b)";
    memccpy(a, b, 'b', sizeof(b)); //a[] = "string(b]"
    printf("memccpy():%s\n", a);
}

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,