#include #include int main(void) {
char *src = \char dest[50]; char *ptr;
ptr = memccpy(dest, src, 'c', strlen(src)); if (ptr) {
*ptr = '\\0';
printf(\} else
printf(\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(\exit(1); /* terminate program if out of memory */ }
/* copy \strcpy(str, \/* display string */
printf(\/* free memory */ free(str);
return 0; }
函数名: memchr
功能: 在数组的前n个字节中搜索字符
用法: void *memchr(void *s, char ch, unsigned n); 程序例: #include #include int main(void) {
char str[17]; char *ptr;
strcpy(str, \ptr = memchr(str, 'r', strlen(str)); if (ptr)
printf(\else
printf(\return 0; }
函数名: memcpy
功能: 从源source中拷贝n个字节到目标destin中
用法: void *memcpy(void *destin, void *source, unsigned n); 程序例: #include #include int main(void) {
char src[] = \char dest[] = \char *ptr;
printf(\ptr = memcpy(dest, src, strlen(src)); if (ptr)
printf(\else
printf(\return 0; }
函数名: memicmp
功能: 比较两个串s1和s2的前n个字节, 忽略大小写
用法: int memicmp(void *s1, void *s2, unsigned n); 程序例: #include #include int main(void) {
char *buf1 = \char *buf2 = \int stat;
stat = memicmp(buf1, buf2, 5);
printf(\if (stat) printf(\
printf(\return 0; }
函数名: memmove 功能: 移动一块字节