當前位置:編程學習大全網 - 電腦編程 - 在線跪求!c語言編程實現兩個字符串連接

在線跪求!c語言編程實現兩個字符串連接

思路:先找到第壹個字符串的結束位置,接著把第二個字符串的所有字符復制到第壹字符串後面,最後加上字符串結束標誌'\0'。

參考代碼:

#include?"stdio.h"?

void?*fun(char?*s1,char?*s2){

int?i=0,j=0;

while(s1[i++]);

i--;

while(s2[j])

s1[i++]=s2[j++];

s1[i]='\0';

}?

int?main()?{

char?a[200],b[100];

gets(a);

gets(b);

fun(a,b);

puts(a);

return?0;

}

/*

運行結果:

qwerewr

asdfghj

qwerewrasdfghj?

*/

  • 上一篇:計算機圖形學與人工智能技術
  • 下一篇:編程fp
  • copyright 2024編程學習大全網