_memccpy函数(memccpy)

该博客介绍了_cmemccpy函数的用法,包括参数解析和返回值说明。函数用于复制内存区域,直到遇到特定字符为止。当找到该字符时,返回目标内存区域中该字符之后的指针。如果未找到指定字符,则返回NULL。

_memccpy
void *_memccpy(
void *dest,
const void *src,
int c,
size_t count
);

Parameters
dest
Pointer to the destination.

src
Pointer to the source.

c
Last character to copy.

count
Number of characters.

Return Value
If the character c is copied, _memccpy returns a pointer to the char in dest that immediately follows the character. If c is not copied, it returns NULL.


```cpp
#include <memory.h>
#include <stdio.h>
#include <string.h>
#include<iostream>

using namespace std;

int main(void)
{
	//char buffer[41] = { '0' };

	char string1[20] = "The qkhh";
	***char buffer[5] = { '0' };***
	char *pdest;

	printf("Function: _memccpy 60 characters or to character ' '\n");
	printf("Source: %s\n", string1);
	pdest = (char *)_memccpy(buffer, string1, 'e', 20);
	cout << pdest << endl;
	//*pdest = '\0';
	printf("Result: %s\n", buffer);
	printf("Length: %d characters\n", strlen(buffer));

	system("pause");
	return 0;
}
输出
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200205005909479.png)

```cpp
#include <memory.h>
#include <stdio.h>
#include <string.h>
#include<iostream>

using namespace std;

int main(void)
{
	//char buffer[41] = { '0' };

	char string1[20] = "The qkhh";
	***char buffer[5];***
	char *pdest;

	printf("Function: _memccpy 60 characters or to character ' '\n");
	printf("Source: %s\n", string1);
	pdest = (char *)_memccpy(buffer, string1, 'e', 20);
	cout << pdest << endl;
	//*pdest = '\0'; 此位置可达到与上面相同输出效果
	printf("Result: %s\n", buffer);
	printf("Length: %d characters\n", strlen(buffer));

	system("pause");
	return 0;
}

输出
在这里插入图片描述
_memccpy函数 若函数在指定空间大小之内遇到指定字符则返回值目标函数的指针,需要将返回值置为‘\0’,否则编译器自动填充,出现错误。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值