_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;
}
输出

```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’,否则编译器自动填充,出现错误。
该博客介绍了_cmemccpy函数的用法,包括参数解析和返回值说明。函数用于复制内存区域,直到遇到特定字符为止。当找到该字符时,返回目标内存区域中该字符之后的指针。如果未找到指定字符,则返回NULL。
1606

被折叠的 条评论
为什么被折叠?



