.
strdup function allocates memory according to the size of input and if memory not available then it will fail,But in case of strcpy while copying the the source string to destination it never checks the size of the destination.So it will be problem if destination size is smaller.
Both copy a string. strcpy wants a buffer to copy into. strdup allocates a buffer using malloc(). Unlike strcpy(), strdup() is not specified by ANSI .
I have a question about this following code.
char a[4] = {"aaa"}; strcpy(a, "bb");
When I do this after function copies bb to the array it puts '\0' ? I mean last for array would be 'b' 'b' 'a' '\0' or 'b' 'b' '\0' '\0'.