我需要你的帮助..
我建立了3个结构:
歌曲,歌曲列表和音乐专辑。
我在ssh中收到消息警告:“来自不兼容指针类型的分配”
根据我旁边写的两行://问题
typedef struct
{
char* nameSong;
char* nameSinger;
int lenghtOfSong;
struct song *next;
struct song *prev;
} song;
typedef struct
{
song* head;
song* tail;
} listOfsong;
typedef struct
{
int yearOfpublication;
listOfsong* listOfSongs;
int numbersOfSongs;
} musicAlbum;
song* SongCreate()
{
song *songInput =(song*) malloc(sizeof(song));
//free
songInput->nameSong = StringName();
songInput->nameSinger = StringName();
scanf("%d", &songInput->lenghtOfSong);
songInput->next = NULL;
songInput->prev = NULL;
return songInput;
}
void AddSongToList(musicAlbum *pmusicAlbum)
{
if (pmusicAlbum->listOfSongs == NULL)
{
pmusicAlbum->listOfSongs = (listOfsong*)malloc(sizeof(listOfsong));
song *newSong=SongCreate();
pmusicAlbum->listOfSongs->head = newSong;
pmusicAlbum->listOfSongs->tail = newSong;
}
else
{
song *newSong = SongCreate();
newSong->prev = pmusicAlbum->listOfSongs->tail;// problem
pmusicAlbum->listOfSongs->tail->next = newSong; // problem
pmusicAlbum->listOfSongs->tail = newSong;
}
}
有人知道这意味着什么吗?
它出现在我项目的其他地方
谢谢 。
最佳答案
改变这个
typedef struct
{
char* nameSong;
char* nameSinger;
int lenghtOfSong;
struct song *next;
struct song *prev;
} song;
至
typedef struct song song;
struct song
{
char* nameSong;
char* nameSinger;
int lenghtOfSong;
struct song *next;
struct song *prev;
};
关于c - ssh中来自不兼容指针类型的赋值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27768783/