c中strcpy函数的等价物,int main和一些解释



函数strpcy()的等价物为:

char *strcpy(char *d, char *s)
{
int i = 0;
while (s[i]) {
d[i] = s[i];
i++;
}
d[i] = ''; // or d[i] = 0;
return d;
}   

为什么它结束了''
两个字符串的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 );
}

相关内容

最新更新