码迷,mamicode.com
首页 > 其他好文 > 详细

Some small problems in C

时间:2019-05-19 10:29:33      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:char   com   follow   returns   cte   nta   some   course   turn   

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.

Some small problems in C

标签:char   com   follow   returns   cte   nta   some   course   turn   

原文地址:https://www.cnblogs.com/lyc4891/p/10888058.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!