當前位置:編程學習大全網 - 網站源碼 - 求c語言答案 實現系統函數strcat,使用字符數組和指針兩種方法實現

求c語言答案 實現系統函數strcat,使用字符數組和指針兩種方法實現

指針實現:char *mystrcat(char *s,char *ct) //字符串連接

{

while(*(s++));

s--;

while(*ct)

*(s++) = *(ct++);

return s;

}數組實現:#include<stdio.h>void mystrcat(char s[],char ct[]) //字符串連接

{

int i;

int length1 = 0,length2 = 0;

while(s[length1++]);

while(ct[length2++]);

length1--;

for(i = length1;i < length1+length2;i++)

s[i] = ct[i-length1];

}int main()

{

char s[100] = "123456";

char ct[] = "dfhjk";

mystrcat(s,ct);

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

return 0;

}

  • 上一篇:我要卸載LINUX下安裝過的JDK,使用命令rpm -qa
  • 下一篇:grep jdk沒東西,怎麽辦
  • copyright 2024編程學習大全網