Some small problems in C

NOW... Actually this 'mystrcpy' is totally correct. The code causes segementation fault is another function 'mystrdup'...

/*/*/*

The first assignment of this course asked me to write some string manipulation functions without using any string library. I got stuck in the function 'mystrcpy'.

I typed following.

/*
* mystrcpy() copies the string pointed to by src (including the terminating character '\0') to the array pointed to by dst.
* Returns: a pointer to the destination string dst.
*/
char *mystrcpy (char *dst, const char *src)
{
  /* Complete the body of the function */

  int i;
  while(src[i]!='\0'){
    dst[i]=src[i];
    i++;
  }
  dst[i]='\0';
  return dst;
}

But terminal showed 'segementation fault'. I'm still thinking about this one.

*\*\*\

posted @ 2019-05-19 07:56  收割稻谷一堆  阅读(93)  评论(0)    收藏  举报