gpt4 book ai didi

c - ssh 中不兼容指针类型的赋值

转载 作者:行者123 更新时间:2023-11-30 17:23:03 24 4
gpt4 key购买 nike

我需要你的帮助..我构建了 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com