0
char *foo(char *dest, const char *src)
{
    unsigned i;
    for (i=0; src[i] != '\0'; ++i)
        dest[i] = src[i];
    dest[i] = '\0';
    return dest;

}

I know that the code is moving through both variable's arrays, and while it's doing that, it makes dest[] have the same character as src[]

How can i do this with pointers instead?

tisaconundrum
  • 2,156
  • 2
  • 22
  • 37

1 Answers1

3

Simply

while (*src != '\0')
    *dst++ = *src++;
*dst = '\0'; // Perhaps you will also need this!

Remember at the end of the loop that dst is pointing to the end of the array not to the begining. And also copy the '\0' terminator, or you don't want to?

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97