1.
#include <stdio.h>
#include <assert.h>
void my_strcpy(char* dest, char* src)
{
assert(dest, src);
while (*src != '\0')
{
*dest = *src;
dest++;
src++;
}
*dest = *src;
}
int main()
{
char arr1[20] = { 0 };
char arr2[] = "hello world";
my_strcpy(arr1, arr2);
printf("%s\n", arr1);
return 0;
}
2.
#include <stdio.h>
#include <assert.h>
void my_strcpy(char* dest, char* src)
{
assert(dest && src);
while (*dest++ = *src++)
{
;
}
}
int main()
{
char arr1[20] = { 0 };
char arr2[] = "hello world";
my_strcpy(arr1, arr2);
printf("%s\n", arr1);
return 0;
}
3.
#include <stdio.h>
#include <assert.h>
char* my_strcpy(char* dest, const char* src)
{
assert(dest && src);
char* ret = dest;
while (*dest++ = *src++)
;
return ret;
}
int main()
{
char arr1[20] = { 0 };
char arr2[] = "hello world";
printf("%s\n", my_strcpy(arr1, arr2));
return 0;
}