strcat

strcat

將兩個char類型連線。 char d[20]="Golden"; char s[20]="View"; strcat(d,s); //列印d printf("%s",d); 輸出 d 為 GoldenView (中間無空格) d和s所指記憶體區域不可以重疊且d必須有足夠的空間來容納s的字元串。 返回指向d的指針。

基本信息

C函式

原型

extern char *strcat(char *dest, const char *src);

頭檔案

在C中,函式原型存在 <string.h>頭檔案中。

在C++中,則存在於<cstring>頭檔案中。

功能

把src所指向的字元串(包括“\0”)複製到dest所指向的字元串後面(刪除*dest原來末尾的“\0”)。要保證*dest足夠長,以容納被複製進來的*src。*src中原有的字元不變。返回指向dest的指針。

說明

src和dest所指記憶體區域不可以重疊且dest必須有足夠的空間來容納src的字元串。

舉例

程式執行結果為:

GoldenGlobalView

Strcat函式原型如下(以下代碼為錯誤代碼,想要通過char *指針修改字元串常量中的字元會導致Segment fault錯誤):

MATLAB函式

定義

strcat 即 Strings Catenate,橫向連線字元串。

語法

combinedStr= strcat( s1, s2, ..., sN)

描述

將數組 s1,s2,...,sN 水平地連線成單個字元串,並保存於變數 combinedStr中。如果任一參數是元胞數組,那么結果 combinedStr 是一個元胞數組,否則, combinedStr是一個字元數組。

實例

>> a = 'Hello'

a =

Hello

>> b = ' Matlab'

b =

Matlab

>> c = strcat(a,b)

c =

Hello Matlab

附註

For character array inputs, strcat removes trailing ASCII white-spacecharacters: space, tab, vertical tab, newline, carriage return, and form-feed. To preserve trailing spaces when concatenating character arrays, use horizontal array concatenation, [ s1, s2, ..., sN]. See the final example in the following section.

For cell array inputs, strcat does not remove trailing white space.

When combining nonscalar cell arrays and multi-row character arrays, cell arrays must be column vectors with the same number of rows as the character arrays.

相關詞條

相關搜尋

熱門詞條

聯絡我們