-1

I have a struct Track with variable like this char artist[81];

I have a function to create a new track Track *newTrack(char *artist, char *title, int time);

But doing this is not possible..

track->artist = artist;

How can I transform a char array into a char?

Aykhan Hagverdili
  • 28,141
  • 6
  • 41
  • 93

2 Answers2

1

you can use strcpy ,

    strcpy(track->artist, artist);

include header

      #include<string.h>
fariz
  • 51
  • 7
1

In this case you can use strcpy in this way:

strcpy(track->artist, artist);

but pay attention:

To avoid overflows, the size of the array pointed by destination shall be long enough to contain the same C string as source (including the terminating null character), and should not overlap in memory with source.

for more details i leave you a useful link : strcpy

Zig Razor
  • 3,381
  • 2
  • 15
  • 35