15 March, 2011

strdup() and strcpy()

whats the difference between strdup() and strcpy()? In which case, which of this is preferred????

2 comments:

  1. strcpy - copy a string to a location YOU created (you create the location, make sure that the source string will have enough room there and afterwards use strcpy to copy)

    strdup - copy a string to a location that will be created by the function. The function will allocate space, make sure that your string will fit there and copy the string. Will return a pointer to the created area.

    ReplyDelete
  2. does it mean that strdup() is better than strcpy()????

    ReplyDelete