strcpy & strncpy

  1. //strcpy
  2. char *strcpy(char *strDest, const char *strSrc);
  3. {
  4.   assert((strDest!=NULL) && (strSrc !=NULL)); 
  5.   char *address = strDest; 
  6.   while( (*strDest++ = * strSrc++) != ‘/0’ ) 
  7.   NULL ; 
  8.   return address ; 
  9. }

 

  1. /*
  2.    Copies count characters from the source string to the destination. 
  3.    If count is less than the length of source,NO NULL CHARACTER is put 
  4.    onto the end of the copied string.If count is greater than the length 
  5.    of sources, dest is padded with null characters to length count.
  6.       把src所指由NULL结束的字符串的前n个字节复制到dest所指的数组中。
  7.    如果src的前n个字节不含NULL字符,则结果不会以NULL字符结束;
  8.    如果src的长度小于n个字节,则以NULL填充dest直到复制完n个字节。
  9.    src和dest所指内存区域不可以重叠且dest必须有足够的空间来容纳src的字符串。
  10.    返回指向dest的指针。
  11. */
  12. char * my_strncpy( char * dest, const char * source, int count )
  13. {
  14.    char *p = dest;
  15.    while (count && (*p++ = *source++)) count--;
  16.    while(count--)
  17.       *p++ = '/0';
  18.    return(dest);
  19. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值