函数 strpcy()
的等效函数是:
char *strcpy(char *d, char *s)
{
int i = 0;
while (s[i]) {
d[i] = s[i];
i++;
}
d[i] = '\0'; // or d[i] = 0;
return d;
}
为什么会结束'\0'
?
对于两个字符串,int main() 应该是什么样子?
最佳答案
发布的代码包含很多不必要的语句。
建议:
char *myStrcpy( char *d, char *s)
{
char *dest = d;
while( *d++ = *s++ );
return dest;
}
如何调用:
#include <stdio.h>
int main( void )
{
char destination[1024];
char source[] = "source string";
myStrcpy( destination, source );
puts( destination );
}
关于c - 相当于c中的strcpy函数,int main以及一些解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53525655/