Implementing a string copy function in C

前端 未结 9 1860
谎友^
谎友^ 2020-12-20 00:57

At a recent job interview, I was asked to implement my own string copy function. I managed to write code that I believe works to an extent. However, when I returned home to

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-20 01:48

    As the other answers have said, you're overwriting the buffer, so for the sake of your test change it to:

    char buffer[ 12 ];
    

    For the job interview they were perhaps hoping for:

    char *mycpy( char *s, char *t )
    {
        while ( *s++ = *t++ )
        {
            ;
        }
        return s;
    }
    

提交回复
热议问题