The easist way would be to use strdup
to duplicate the strings.
d->artist = strdup(s->artist);
d->title = strdup(s->title);
To fix your actual problem, you need to use strlen
and not sizeof
.
d->artist = malloc(strlen(s->artist) + 1) ;
strcpy(d->artist, s->artist);
d->title = malloc(strlen(s->title) + 1) ;
strcpy(d->title, s->title);
The problem is that this:
sizeof(*s->artist)
Is returning sizeof(char)
, which is most likely 1.