下面的程序有什么问题?
main( )
{
char *str1 = "United" ;
char *str2 = "Front" ;
char *str3 ;
str3 = strcat ( str1, str2 ) ;
printf ( "\n%s", str3 ) ;
}
我无法编译上面的程序,它总是给我运行时错误。我正在尝试连接两个字符串。上面的程序有没有错误?
Thanks.
做你的char *str1 = "United"
as
char str1[<required memory for concatenated resultant string>] = "United"
.
您需要为目标缓冲区分配内存,即str1
. str3
还将收到地址str1
在结果中。 “strcat”不会检查目标缓冲区 (str1) 中的空间可用性。程序员必须照顾它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)