首页 > 试题广场 >

不调用C++C的字符串库函数, 以CC++语言的角度,编

[问答题]
不调用C++/C的字符串库函数, C/C++语言的角度,编写strcpy函数。
请写出:
(1)实现思路;
(2)注意事项;
(3)具体实现程序。

 1 #include <stdio.h>
  2 
  3 int mycpy(char * out, char *src)
  4 {
  5     int n = 0;
  6     while(*src){
  7         *out++ = *src++;
  8         n++;
  9     }
 10     return n;
 11 }
 12 int main(void)
 13 {
 14     char* src = "123456789abcdef";
 15     char out[15] = "";
 16     mycpy(out, src);
 17     printf("out:%s\n", out);
 18 }
~                                                                                                                     
~                                     
发表于 2019-10-07 11:12:49 回复(0)