strcpy using pointers

前端 未结 7 1066
无人及你
无人及你 2021-01-13 11:29

I\'m trying to write strcpy on my own using pointers and I get an error during runtime.

void str_cpy(char **destination, const char *source) {
//    char *s1         


        
相关标签:
7条回答
  • 2021-01-13 12:34

    For simplicity's sake, this can be done in one line in a function.

    void mystrcpy(char *dest, const char *src) {
      while (*dest++ = *src++);
    }
    

    This being said, you do need to allocate memory for dest beforehand using malloc or just simply by having a character array like char dest[256].

    0 讨论(0)
提交回复
热议问题