小编mal*_*ode的帖子

我制作了自己的 strcpy 函数,但它不起作用。如何修复它?

我尝试创建自己的mystrcpy()函数,它采用与标准函数相同的参数。它没有响应。该数组不会被复制。

size_t Mystrlen(const char* s)
{
    int i = 0;
    while (s[i] != '\0')
    {
        i++;
    }
    return i;
}

char* Mystrcpy(char* s1, const char* s2)
{
    for (int i = 0; i < Mystrlen(s2); i++)
        s1[i] = s2[i];
    return s1;
}

int main()
{
    char s1[50];
    char s2[50];
    cout << "enter the value of second string\n";
    cin >> s2;
    Mystrcpy(s1, s2);
}
Run Code Online (Sandbox Code Playgroud)

https://godbolt.org/z/zWxqxn3Kx

c++ function char strcpy

-1
推荐指数
1
解决办法
289
查看次数

标签 统计

c++ ×1

char ×1

function ×1

strcpy ×1