Welcome Guest.

2Answers

Sstrcpy function:

Asked by: Sharon Mitchell 224 views IT November 29, 2018

void sstrcpy(char *s,char *t)

{

 while(*s!='\0')

{

*s= *t;

s++;

t++;

}

*s=0;

}

 

int main( )

{

char str1[100], Str2[]="abcdefgh";

    sstrcpy(str1,str2);

    printf("%s\n",str1);

   return 0;

}

subscript 0    1    2   3   4    5   6   7   8

*t    a

str1[]                                           0

sstrcpy function:

Addition: Find the subscript 0 1 2 3 4 5 6 7 8 *t astr1[] 0 Corresponding value

2 Answers

  1. +4Votes  

    The loop process and the contents of the final str1 (subscripts from 0 to 8) are respectively (each step of *t is also)

    abcdefgh \0

    Question: *t is abcdefgh?
    What is str1?

    Answer: *t is a b c d e f g h and \0 at each step of the loop
    After the end of the loop is \0
    And str1’s [0]~[8] are also
    a b c d e f g h and \0
    One step in the loop, s [subscript] = * t content

    Lewis- November 29, 2018 |

  2. +2Votes  

    strcpy is a standard library function of C language, strcpy puts a string starting from src address and containing ‘\0’ terminator Copy to the address space starting with dest, the return value is of type char*.

    Kevin Scott- November 30, 2018 |