Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4460959
  • 博文数量: 356
  • 博客积分: 10458
  • 博客等级: 上将
  • 技术积分: 4734
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-24 14:59
文章分类

全部博文(356)

文章存档

2020年(17)

2019年(9)

2018年(26)

2017年(5)

2016年(11)

2015年(20)

2014年(2)

2013年(17)

2012年(15)

2011年(4)

2010年(7)

2009年(14)

2008年(209)

分类: C/C++

2008-05-31 14:27:20

C语言库函数源代码】

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

/*

   Copies count characters from the source string to the destination.

   If count is less than the length of source,NO NULL CHARACTER is put

   onto the end of the copied string.If count is greater than the length

   of sources, dest is padded with null characters to length count.

      把src所指由NULL结束的字符串的前n个字节复制到dest所指的数组中。

   如果src的前n个字节不含NULL字符,则结果不会以NULL字符结束;

   如果src的长度小于n个字节,则以NULL填充dest直到复制完n个字节。

   src和dest所指内存区域不可以重叠且dest必须有足够的空间来容纳src的字符串。

   返回指向dest的指针。

*/

char * my_strncpy( char * dest, const char * source, int count )

{

   char *p = dest;

   while (count && (*p++ = *source++)) count--;

   while(count--)

      *p++ = '\0';

   return(dest);

}

int main()

{

   char a[20];

   puts(my_strncpy(a,"ammana_babi",15));

   system("pause");

   return 0;

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

chinaunix网友2008-05-31 14:45:35

转帖的,帖子上有原地址的. 我自己有个疑问: 如果长度不够为什么不加\0