strcpy vs strdup

前端 未结 5 1923
抹茶落季
抹茶落季 2020-11-28 02:48

I read that strcpy is for copying a string, and strdup returns a pointer to a new string to duplicate the string.

Could you please explain

5条回答
  •  一向
    一向 (楼主)
    2020-11-28 03:22

    char *strdup(char *pszSrch);

    strdup will allocate storage the size of the original string. If storage allocation is successful, the original string is copied to the duplicate string.

    strdupd return NULL on failure. If memory is not allocated, copy fails strdup return NULL.

提交回复
热议问题