gpt4 book ai didi

c - 编写 strcpy 的替代品

转载 作者:太空宇宙 更新时间:2023-11-04 05:36:29 24 4
gpt4 key购买 nike

我必须在不使用指针或具有返回值的函数的情况下编写 strcpy 的替代品...这怎么可能?!

这是我目前所拥有的,但它使用了返回值。

void str_copy(char destination [], char source []) {
int i;
for (i = 0; source[i] != '\0'; ++i)
destination[i] = source[i];
destination[i] = '\0';
return destination;
}

最佳答案

只需删除 return 语句即可。

函数如下所示

void str_copy( char destination [], const char source [] ) {
size_t i = 0;
while ( destination[i] = source[i] ) i++;
}

关于c - 编写 strcpy 的替代品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33816825/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com