当前位置:网站首页>6-5 string - 2 String copy (assignment) (10 points) the C language standard function library includes the strcpy function for string copy (assignment). As an exercise, we write a function with the sam

6-5 string - 2 String copy (assignment) (10 points) the C language standard function library includes the strcpy function for string copy (assignment). As an exercise, we write a function with the sam

2022-04-23 20:27:00 Tomatos_ baby

C The language standard function library includes strcpy function , For string copying ( assignment ). As a practice , We write a function with the same function .

The function prototype

char* StrCpy(char *dst, const char *src);

explain :src Is the starting address of the source string ,dst The starting address of the string for the purpose , Function will src Copy string to dst strand , Function value is dst.

judging procedures

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

char* StrCpy(char *dst, const char *src);

int main()
{
    char a[1024], b[1024], c[1024];
    gets(a);
    StrCpy(c, StrCpy(b, a));
    puts(a);
    puts(b);
    puts(c);
    return 0;
}

/*  The code you submit will be embedded here  */

sample input

abcd

sample output

abcd
abcd
abcd
char* StrCpy(char *dst, const char *src)
{
    int i,j;
    for(i=0,j=0;src[i]!='\0';i++)
    {
        dst[j]=src[i];
        j++;
    }
    dst[j]='\0';
    return dst;
}

 

版权声明
本文为[Tomatos_ baby]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204232022015387.html