字串的連線strcat 自實現

2021-08-10 17:43:30 字數 950 閱讀 1731

#include "stdafx.h"

#include int _tmain(int argc, _tchar* argv)

p++; q++;

} printf("%s\n", firstname);

方法二:

char* p = firstname;

while (*p != '\0') p++; //p為得到jim的\0位置

char* q = lastname;

for (; *p = *q; p++, q++); //中間條件為,右給左賦值後

//判斷左值是否等於0 不為0則繼續執行

printf("%s\n", firstname);

方法三:

char* p;

for (p=firstname; *p != '\0'; p++);

for (char* q = lastname; *p = *q; p++, q++);

printf("%s\n", firstname);

#endif

strcat(firstname, lastname); //系統函式 將倆個字串連線起來

printf("%s\n", firstname);

//指標++的位置問題

char text = "bbbbbbb";

char *t = text;

while (*t != 'b') t++; //t++在外,迴圈結束時t指向第乙個b的位置

printf("t=%p text=%p\n", t, text);

t = text;

while (*t++ != 'b'); //t++在內,迴圈結束時t指向第二個b的位置

printf("t=%p text=%p\n", t, text);

return 0;

}

c 實現字串strcat 連線

字串連線函式 include includeusing namespace std char string cat char source,int s1,const char dest return source int main sum strlen a 計算a陣列的字元數 string cat ...

C語言strcat 函式 連線字串

標頭檔案 include strcat 函式用來連線字串,其原型為 char strcat char dest,const char src 引數 dest 為目的字串指標,src 為源字串指標。strcat 會將引數 src 字串複製到引數 dest 所指的字串尾部 dest 最後的結束字元 nu...

C語言strcat 函式 連線字串

標頭檔案 include strcat 函式用來連線字串,其原型為 char strcat char dest,const char src 引數 dest 為目的字串指標,src 為源字串指標。strcat 會將引數 src 字串複製到引數 dest 所指的字串尾部 dest 最後的結束字元 nu...