strcat函数
函数原型:extern char *strcat(char *dest,char *src)
#include<string.h>
#include<stdio.h>
int main()
{
char dest[100]="Hello,I am sky2098,I liking programing!"; //这里我们开辟了100个字节的空间,远远多于该字符串的空间大小,已备后面连接字符串后空间够用
char *src="gramk";
char *temp;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
temp=strcat(dest,src);
if(temp!=NULL)
{
printf("%s ",temp);
}
else
{
printf("You cause an error! ");
}
return 0;
}
参数说明:dest为一个目的字符串的指针,即被连接的字符串(在前),src为一个源字符串的指针(在后)。
所在库名:#include <string.h>
函数功能:把src所指字符串添加到dest结尾处实现字符串的连接,连接过程覆盖dest结尾处的'/0'。
返回说明:src和dest所指内存区域不可以重叠,并且dest必须有足够的空间来容纳src的字符串返回指向dest的指针。
其它说明:暂时无。
实例:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
在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”的空间大小,所以无法实现连接功能。
Keep it simple!