博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
strcpy & strncpy
阅读量:4168 次
发布时间:2019-05-26

本文共 824 字,大约阅读时间需要 2 分钟。

  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. }

转载地址:http://xdgxi.baihongyu.com/

你可能感兴趣的文章
Xcode 11 报错,提示libstdc++.6 缺失,解决方案
查看>>
vue项目打包后无法运行报错空白页面
查看>>
1136 . 欧拉函数
查看>>
面试题:强制类型转换
查看>>
Decorator模式
查看>>
Template模式
查看>>
Observer模式
查看>>
高性能服务器设计
查看>>
图文介绍openLDAP在windows上的安装配置
查看>>
Pentaho BI开源报表系统
查看>>
Pentaho 开发: 在eclipse中构建Pentaho BI Server工程
查看>>
android中SharedPreferences的简单例子
查看>>
android中使用TextView来显示某个网址的内容,使用<ScrollView>来生成下拉列表框
查看>>
andorid里关于wifi的分析
查看>>
Spring MVC和Struts2的比较
查看>>
Hibernate和IBatis对比
查看>>
Spring MVC 教程,快速入门,深入分析
查看>>
Android 的source (需安装 git repo)
查看>>
LOCAL_PRELINK_MODULE和prelink-linux-arm.map
查看>>
Ubuntu Navicat for MySQL安装以及破解方案
查看>>