c語言實現strcp函數

#include <stdio.h> #include <string.h>
void main() { char *strcopy(char *target, char *source); char a[] = "hello world~"; strcopy(a,"thanks!"); printf("%s\n",a); getchar(); } char *strcopy(char *target,char *source) { char *p = target; if (strlen(target) < strlen(source)) { return NULL; } while (*target++ = *source++) { if (*source == '\0') { break; } } *target = '\0'; return p; }
相關文章
相關標籤/搜索