Like a question below, i have to use the pointer concept to copy array from one to another in mystrcpy2 function, unlike mystrcpy function that does not use the pointer concept. Anyway, I typed my answer, " dest = src;" which seemed to be overly simple but right answer for me. But when I type in the input, like "Hello World", it shows like "Hello World ???" like strange letters in the back. But when I type short words like "abc", the result is exactly "abc." Is it simply a matter of computer or did I do something wrong?
I"m also wondering if "while (*src) *dest++=*src++;" works as well?
/*Complete the mystrcpy2() function that copies the null-terminated string pointed by src to the string pointed by dest. The mystrcpy2() should give the same result with the mystrcpy() that uses an index based array traversal approach. Note that adding local variables are not allowed in implementing the mystrcpy2(). Write and submit the source code of your "mystrcpy2()" function. */
#include <stdio.h>
void mystrcpy(char dest[], char src[])
{
int i=0,j=0;
while (src[i])
dest[j++] = src[i++];
}
void mystrcpy2(char *dest, char *src)
{
dest = src;
}
int main(void)
{
char mystr1[256];
char mystr2[256];
gets(mystr1);
mystrcpy(mystr2, mystr1);
puts(mystr2);
mystrcpy2(mystr2, mystr1);
puts(mystr2);
return 0;
}