strcat strncat的使用方法
2014-06-29 01:53
295 查看
SYNOPSIS
strcat 把源字符串连接到目的字符串,并且覆盖目的字符串的'\0',并且在连接后的字符串添加一个'\0',所以,要用这个函数,目的字符串剩余空间大小,必须大于源字符串有效字符个数加一
strncat 把源字符串连接到目的字符串,并且覆盖目的字符串的'\0'。不同点是,strncat最多从源字符串中取出n个字节的内容,如果源字符串的大小大于n个字节,那么strncat就截取n个字节,并且在字符串末尾添加'\0'
#include <string.h> char *strcat(char *dest, const char *src); char *strncat(char *dest, const char *src, size_t n);
strcat 把源字符串连接到目的字符串,并且覆盖目的字符串的'\0',并且在连接后的字符串添加一个'\0',所以,要用这个函数,目的字符串剩余空间大小,必须大于源字符串有效字符个数加一
strncat 把源字符串连接到目的字符串,并且覆盖目的字符串的'\0'。不同点是,strncat最多从源字符串中取出n个字节的内容,如果源字符串的大小大于n个字节,那么strncat就截取n个字节,并且在字符串末尾添加'\0'
STRCAT(3) Linux Programmer's Manual STRCAT(3) NAME strcat, strncat - concatenate two strings SYNOPSIS #include <string.h> char *strcat(char *dest, const char *src); char *strncat(char *dest, const char *src, size_t n); DESCRIPTION The strcat() function appends the src string to the dest string, overwriting the null byte ('\0') at the end of dest, and then adds a terminating null byte. The strings may not overlap, and the dest string must have enough space for the result. The strncat() function is similar, except that * it will use at most n characters from src; and * src does not need to be null-terminated if it contains n or more characters. As with strcat(), the resulting string in dest is always null-terminated. If src contains n or more characters, strncat() writes n+1 characters to dest (n from src plus the terminating null byte). Therefore, the size of dest must be at least strlen(dest)+n+1. A simple implementation of strncat() might be: char* strncat(char *dest, const char *src, size_t n) { size_t dest_len = strlen(dest); size_t i; for (i = 0 ; i < n && src[i] != '\0' ; i++) dest[dest_len + i] = src[i]; dest[dest_len + i] = '\0'; return dest; } RETURN VALUE The strcat() and strncat() functions return a pointer to the resulting string dest.
相关文章推荐
- Ghost8.0详细使用方法与命令行参数
- Delphi5 企业版使用BDE访问 Oracle方法
- TListView组件使用方法
- Jakarta Commons Digester 简介和具体使用方法
- 如何使用vs.net生成方法的小技巧
- SCI软件使用方法总结-定位测量篇
- 第三方控件使用方法
- JSP数据和JavaScirpt数据交互使用问题的一种解决方法
- 在delphi中使用xml文档有两种方法
- 水晶报表使用经验谈1--建立水晶报表第一步及编译最易出现错误的解决方法及报表转换成pdf文档进行打印方法
- 关于Delphi中预编译指令的使用方法
- showModalDialog()、showModelessDialog()方法使用详解
- 非窗口类中使用定时器的方法(二)
- 效率和方便性--怎样在没有限制类可用性的情况下使用本地方法
- [导入]showModalDialog()、showModelessDialog()方法使用详解
- 使用数据库保存session的方法
- ASP的技术特点与使用方法
- 在RxRichEdit中插入图片的完美解决方法(不使用剪贴板)
- 使用5种不同的方法加载水晶报表(Windows 窗体)
- 简介使用ASP.NET访问Oracle数据库的方法