background image

char *ptr;
ptr = memccpy(dest, src, 'c', strlen(src));
if (ptr)
{
*ptr = '\0';
printf("The character was found: %s\n", dest);
}
else
printf("The character wasn't found\n");
return 0;
}
函数名: malloc
功能: 内存分配函数
用法: void *malloc(unsigned size);
程序例:
#include
#include
#include
#include
int main(void)
{
char *str;
/* allocate memory for string */
/* This will generate an error when compiling */
/* with C++, use the new operator instead.*/
if ((str = malloc(10)) == NULL)
{
printf("Not enough memory to allocate buffer\n");
exit(1); /* terminate program if out of memory */
}
/* copy "Hello" into string */
strcpy(str, "Hello");
/* display string */
printf("String is %s\n", str);
/* free memory */
free(str);
return 0;
}
函数名: memchr
功能: 在数组的前 n 个字节中搜索字符
用法: void *memchr(void *s, char ch, unsigned n);
程序例:
#include
#include