Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1396127
  • 博文数量: 143
  • 博客积分: 10005
  • 博客等级: 上将
  • 技术积分: 1535
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-23 17:25
个人简介

淡泊明志 宁静致远

文章分类

全部博文(143)

文章存档

2011年(2)

2009年(1)

2007年(22)

2006年(118)

我的朋友

分类: C/C++

2006-11-25 15:35:39

C语言库函数源代码】

【本程序在Dev C++ 4.9.9.2 下编译通过】

/*

   Sets the first "count" bytes of the memory starting at "dst" to the character value "val".

   把dst所指内存区域的前count个字节设置为val。返回指向dst的指针。

   在实际应用中,我们有时候会用malloc函数来申请一些内存空间,这个内存空间有时候需要初始化,常用memset来进行初始化。

   如:

   int *p;

   p = (int *)malloc( 0x400 * sizeof(int));

   memset(p,0,0x400);

*/

void * my_memset(void *dst,int val,int count)

{

   void *p = dst;

   while (count--)

   {

      *(char *)dst = (char)val;

        dst = (char *)dst + 1;

   }

   return p;

}

int main()

{

   char str[] ="ammana_babi";

   my_memset(str,'z',strlen(str));

   puts(str);

   system("pause");

   return 0;

}

阅读(4861) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~