该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#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
int main(void)
{
char str[17];
char *ptr;
strcpy(str, "This is a string");
ptr = memchr(str, 'r', strlen(str));
if (ptr)
printf("The character 'r' is at position: %d\n", ptr - str);
else
printf("The character was not found\n");
return 0;
} 函数名: memcpy 功能: 从源source中拷贝n个字节到目标destin中用法: void *memcpy(void *destin, void *source, unsigned n); 程序例: #include
#include
int main(void)
{
char src[] = "******************************";
char dest[] = "abcdefghijlkmnopqrstuvwxyz0123456709";
char *ptr;
printf("destination before memcpy: %s\n", dest);
ptr = memcpy(dest, src, strlen(src));
if (ptr)
printf("destination after memcpy: %s\n", dest);
else
printf("memcpy failed\n");
return 0;
} 函数名: memicmp 功能: 比较两个串s1和s2的前n个字节, 忽略大小写用法: int memicmp(void *s1, void *s2, unsigned n); 程序例: #include
#include
int main(void)
{
char *buf1 = "ABCDE123";
char *buf2 = "abcde456";
int stat;
stat = memicmp(buf1, buf2, 5);
printf("The strings to position 5 are ");
if (stat)
printf("not ");
printf("the same\n");
return 0;
} 函数名: memmove 功能: 移动一块字节用法: void *memmove(void *destin, void *source, unsigned n); 程序例: #include
#include
int main(void)
{
char *dest = "abcdefghijklmnopqrstuvwxyz0123456789";
char *src = "******************************";
printf("destination prior to memmove: %s\n", dest);
memmove(dest, src, 26);
printf("destination after memmove: %s\n", dest);
return 0;
} 函数名: memset 功能: 设置s中的所有字节为ch, s数组的大小由n给定用法: void *memset(void *s, char ch, unsigned n); 程序例: #include
#include
#include
int main(void)
{
char buffer[] = "Hello world\n";
printf("Buffer before memset: %s\n", buffer);
memset(buffer, '*', strlen(buffer) - 1);
printf("Buffer after memset: %s\n", buffer);
return 0;
} 函数名: mkdir 功能: 建立一个目录用法: int mkdir(char *pathname); 程序例: #include
#include
#include
#include
int main(void)
{
int status;
clrscr();
status = mkdir("asdfjklm");
(!status) ? (printf("Directory created\n")) :
(printf("Unable to create directory\n"));
getch();
system("dir");
getch();
status = rmdir("asdfjklm");
(!status) ? (printf("Directory deleted\n")) :
(perror("Unable to delete directory"));
return 0;
} 函数名: mktemp 功能: 建立唯一的文件名用法: char *mktemp(char *template); 程序例: #include