习题8-5 使用函数实现字符串部分复制
1 void strmcpy(char *t, int m, char *s) 2 { 3 int len = 0; //计算字符串t的长度 4 char *p = t; 5 int i; 6 while (*p != '\0') 7 { 8 len++; 9 p++; 10 } 11 12 if (m <= len) 13 { 14 for (i = 0; t[m - 1 + i] != '\0'; i++) 15 { 16 s[i] = t[m - 1 + i]; 17 } 18 s[i] = '\0'; 19 } 20 else 21 { 22 *s = '\0'; 23 } 24 }