Other contributors have said "Difference between strdup and strcpy?" is the same question as "What are the differences between strdup and strcpy functions used in C?" If you believe that these are not asking the same thing and should be answered differently, click here

What are the differences between strdup and strcpy functions used in C?

Answer:

Answer

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.

First answer by Dgabrov. Last edit by Dgabrov. Contributor trust: 118 [recommend contributor recommended]. Question popularity: 26 [recommend question].