string - strncat源码
2015-07-29 10:23
176 查看
[code]// // main.cpp // AUTO_PRO // // Created by yanzhengqing on 12-12-11. // Copyright (c) 2012年 yanzhengqing. All rights reserved. // #include using namespacestd; /*** *char *strncat(front, back, count) - append count chars of back onto front * *Purpose: * Appends at most count characters of the string back onto the * end of front, and ALWAYS terminates with a null character. * If count is greater than the length of back, the length of back * is used instead. (Unlike strncpy, this routine does not pad out * to count characters). * *Entry: * char *front - string to append onto * char *back - string to append * unsigned count - count of max characters to append * *Exit: * returns a pointer to string appended onto (front). * *Uses: * *Exceptions: * *******************************************************************************/ ///////////////////////////////////////////////////////////////////////////////// /*说明: 1. __cdecl 是C Declaration的缩写(declaration,声明),表示C语言默认的函数调用方法:所有参数从右到左依次入栈,这些参数由调用者清除,称为手动清栈。被调用函数不会要求调用者传递多少参数,调用者传递过多或者过少的参数,甚至完全不同的参数都不会产生编译阶段的错误。 2. 在字符串dest之后连接上src,最多增加n个字符 3. 按照ANSI(American National Standards Institute)标准,不能对void指针进行算法操作,即不能对void指针进行如p++的操作,所以需要转换为具体的类型指针来操作,例如char *。(引用网友的结论) 4. size_t 类型定义在cstddef头文件中,该文件是C标准库的头文件stddef.h的C++版。它是一个与机器相关的unsigned类型,其大小足以保证存储内存中对象的大小。 */ char * __cdecl strncat ( char * front, const char * back, size_t count ) { char *start = front; while (*front++); front--; while (count--) if (!(*front++ = *back++)) return(start); *front ='\0'; return(start); } int main() { char brc[50] ="blog.csdn.net/barry_yan"; constchar src[50] ="/you are a good boy!!"; cout<endl; cout<endl; strncat(brc,src,strlen(src)); cout<endl; return 0; }
相关文章推荐
- JS ZTREE 的用法
- JQuery常用的几种显示隐藏的方法
- TP中用D方法创建了模型后,为何调用不了creat,add等方法??!
- 文章4片 观察者模式
- 时序js插件cubism使用
- Android动画初学
- HDU 1864 最大报销额
- Linux下多线程调试的一些方法
- mvc用UpdateModel报错
- run sharepoint ise会报不可识别的错误的解决方法
- 制作树莓派镜像img,并在其他新板上使用,实现批量克隆树莓派板
- eclipse拆分窗口
- 扩展逻辑卷命令
- CMFCColorButton
- SIP中的SDP offer/answer交换初探
- 大神X7手机刷机/救砖/无法开机/请连接手机
- 为什么C++编译器不支持模板头文件和实现代码分离的编译
- App crash原因以及解决办法
- Apache安全和强化的十三个技巧
- 至屠夫徐五家见悬此联