电脑上M开头的C语言,C语言函数大全(m开头)

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值