c语言中strcpy函数,函数原型、头文件

1、函数原型。

#include <stdio.h>

char *strcpy(char *s1, const char *s2)
{
    char *t = s1;
    
    while(*s1++ = *s2++)
        ;
    return t;
}

int main(void)
{
    char str1[128] = "abcde";
    char str2[128];
    printf("str2: "); scanf("%s", str2);
    
    strcpy(str1, str2);
    printf("copy result str1: %s
", str1);
    return 0;
}

2、头文件

#include <stdio.h>
#include <string.h>

int main(void)
{
    char str1[128] = "abded";
    char str2[128];
    printf("str2: "); scanf("%s", str2);
    
    strcpy(str1, str2);
    
    printf("cp result str1: %s
", str1);
    return 0;
}

原文地址:https://www.cnblogs.com/liujiaxin2018/p/14843183.html