strcat函数
来源:互联网 发布:linux怎么删除多个文件 编辑:程序博客网 时间:2024/05/12 21:48
函数原型: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函数的使用
- 对“缓存”的全面理解和优化
- csh debug
- C语言联合体union
- 325. Nothing seed, nothing find. 没有追求,没有收获
- strstr函数
- strcat函数
- C#编写Windows服务及安装
- Android的联通性---Bluetooth(二)
- iPhone开发--更改xcode中的Apple ID
- Oracle中编辑、运行语句和命令
- strcpy,stpcpy函数
- windows7(x64) 家庭版+vs2010旗舰版安装
- 优秀的软件企业为何倒下?
- strcmp函数