2016-04-10 81 views
1

enter image description hereCON-CAT /追加字符串流用C

我會怎麼做c中的圖像上顯示的例子。即將字符串連接/附加到一個字符串。字符串從char *數組中出來;下面的功能會起作用嗎?由於

ptr = strcat(s1, s2); 

我想打印加入字符串,然後

printf("the string is = %s ",joinedstring); 
+0

http://stackoverflow.com/q/11583613/971127 – BLUEPIXY

回答

0

strcat預計s1足夠長,以適應所有級聯的結果。這意味着目標的長度必須爲17個字符,因爲該字符串有16個字符,並且您還需要一個空白終止符char

此外,結果必須以空字符串開頭,就像這樣:

char res[17] = {0}; 
strcat(res, "this"); 
strcat(res, ":"); 
strcat(res, "is"); 
... // and so on