#include<stdio.h> //如果一個數組做為函數的形參傳遞,那么數組可以在被調用的函數中修改 //有時候不希望這個事發生,所以對形參采用const參數 //size_t strlen(const char *s); //strcpy(char* s1,const char* s2); void mystrcat(char *s1,const char *s2) {int len = 0;while(s2[len]){len++;}while(*s1){s1++;}int i;for(i = 0; i < len; i++){*s1 = *s2;s1++;s2++;} }int main() {char s1[10] = "123";char s2[10] = "456";mystrcat(s1,s2);printf("s1 = %s\n",s1);return 0; }
?