用指针形式写一个strcpy函数。

strcpy函数

#include<stdio.h>
char *mystrcpy(char *str, const char *ptr)
{
  char *tmp = str;
  while((*str++ = *ptr++) != '\0');
  return tmp;
}

int main()
{
   char str[20] = "helloworld";
   char ptr[20] = "world";
   mystrcpy(str, ptr);
   printf("%s\n", str);
   return 0;
}

这里写图片描述

猜你喜欢

转载自blog.csdn.net/SRXxxx1111/article/details/81807411