cstrcat函式怎麼用,C strcat函式問題

時間 2021-07-08 20:33:03

1樓:匿名使用者

原型extern char *strcat(char *dest,char *src);

用法#include

功能把src所指字串新增到dest結尾處(覆蓋dest結尾處的'\0')並新增'\0'。

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

返回指向dest的指標。

舉例char str4 = "hello world";

char str5 = "hello world";

cout << strcat(str4,str5) << endl;

會出錯,因為str4沒有足夠的空間

下面是我自己的一個實現,不足之處,還望指正!!!

複製****如下:

#include "stdafx.h"

#include

#include

using namespace std;

//連線字串

char* mystrcat(char* deststr,const char* srcstr) //如果兩個字串是同一個字串呢?

while(*deststr++ = *srcstr++)

null;

return temp; //為了實現鏈式操作,將目的地址返回

}int _tmain(int argc, _tchar* argv)

2樓:匿名使用者

函式原型:extern char *strcat(char *a,char *b);

用法:#include ,需要引入頭問題。

功能:去掉a字串的結束標誌'\0',並把a字串新增到b字串的開始位置。

返回值:指向a的指標。

注意:a必須有足夠的空間來容納b的字串。

#include

#include

using namespace std;

int main(){

char a[20]="hello ";

char b[7]="world!";

cout<

c++ strcat函式問題

3樓:

strcat 系統裡有現成的,不需要另寫。

字串長度 用 strlen() 計算。或者 自己 判斷 i=0; while (1) .

由於引數是指標,在你的函式內,是沒有辦法測定 p1 陣列 大小的。

除非 你把陣列大小也用引數傳進函式。

strcat函式 很簡單,

void my_strcat(char* p1,char* p2);j=0; while (1) ;

}#include

#include

#include

using namespace std;

int main ()

printf("%d\n",i);

strcat(str1,str2); // 系統裡已有// my_strcat(str1,str2); // 用自己寫的也可以

cout << str1;

return 0;}

4樓:

strlen函式來求

這個函式什麼用,什麼是函式怎麼用函式計算

鳳樹枝惠緞 void invalidate bool berase true 該函式的作用是使整個視窗客戶區無效。視窗的客戶區無效意味著需要重繪,例如,如果一個被其它視窗遮住的視窗變成了前臺視窗,那麼原來被遮住的部分就是無效的,需要重繪。這時windows會在應用程式的訊息佇列中放置wm paint...

怎麼把linux上的UTC時間改成CST時間

root localhost date fri apr 14 23 26 05 edt 2006 edt 美國 東區時區 root localhost date s 2011 9 30 fri sep 30 00 00 00 edt 2011 root localhost date s 14 18 ...

ecelvlookup函式怎麼用

excel vlookup函式的使用步驟如下 1.為此在單元格中輸入 vlookup 此時就會發現vlookup包括三個引數和一個可選引數。2.其中 lookup value 是指要查詢的值,在此為 c 3.引數 table array 是指搜尋的區域,在此在除標題之後的整個資料區域。4.第三個引數...