strcat函数
来源:互联网 发布:linux用vi创建文件 编辑:程序博客网 时间:2024/06/05 03:45
函数原型:extern char *strcat(char *dest,char *src)
参数说明:dest为一个目的字符串的指针,即被连接的字符串(在前),src为一个源字符串的指针(在后)。
所在库名:#include <string.h>
函数功能:把src所指字符串添加到dest结尾处实现字符串的连接,连接过程覆盖dest结尾处的'/0'。
返回说明:src和dest所指内存区域不可以重叠,并且dest必须有足够的空间来容纳src的字符串返回指向dest的指针。
其它说明:暂时无。
实例:
#include<string.h>
#include<stdio.h>
int main()
...{
char dest[100]="Hello,I am sky2098,I liking programing!"; //这里我们开辟了100个字节的空间,远远多于该字符串的空间大小,已备后面连接字符串后空间够用
char *src="gramk";
char *temp;
temp=strcat(dest,src);
if(temp!=NULL)
...{
printf("%s ",temp);
}
else
...{
printf("You cause an error! ");
}
return 0;
}
#include<stdio.h>
int main()
...{
char dest[100]="Hello,I am sky2098,I liking programing!"; //这里我们开辟了100个字节的空间,远远多于该字符串的空间大小,已备后面连接字符串后空间够用
char *src="gramk";
char *temp;
temp=strcat(dest,src);
if(temp!=NULL)
...{
printf("%s ",temp);
}
else
...{
printf("You cause an error! ");
}
return 0;
}
在VC++ 6.0 编译运行:
如果最初为dest分配空间不足时,比如我们这样:
char *dest="Hello,I am sky2098,I liking programing!";
连接字符串时就会发生异常:
通过char *dest="Hello,I am sky2098,I liking programing!";我们只是为dest分配了strlen("Hello,I am sky2098,I liking programing!")+1;个字节空间,而连接是在dest的“/0”上覆盖,而此时只有一个“/0”的空间大小,所以无法实现连接功能。
- strcat函数
- strcat() 函数
- strcat函数
- strcat函数
- strcat函数
- strcat()函数
- strcat函数
- strcat函数
- strcat函数
- strcat函数
- strcat函数
- strcat 函数
- strcat 函数
- strcat 函数
- strcat函数
- strcat()函数
- strcat函数 strncat函数
- strcat函数的使用
- 出差时的催眠的六大法宝
- PHP 中的 XML 拉模式解析
- 应用软件的组合技术:用XML描述你的框架(一)
- 导入SQLSERVER备份文件问题
- 上班人员必读:“五险一金”详解
- strcat函数
- js遍历表格的例子
- Flex2 event - Notes
- 在 WebSphere Federation Server V9.1 中异步执行联邦查询
- 注释代码
- 内心的震憾与内疚
- Portlet 开发工作手册
- [ZT]迅雷的工作原理
- Simple Persistence for Java 的零配置对象持久性