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\n", 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\n", str1);
    return 0;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM