私はこのサイトを初めて利用し、アーティスト名、曲名、アルバム名、日付、および実行時間とともにMp3を格納する二重リンクリストに関するヘルプを探しています。少しでも手伝っていただければ幸いです。add関数でGDBによるセグメンテーション違反が発生しています。
警告も次のとおりです。
Description Resource Path Location Type
'data' is used uninitialized in this function [-Wuninitialized] Mp3.c /OperatingSystemsLab1
line 7 C/C++ Problem
assignment makes pointer from integer without a cast [enabled by default] Mp3.c /OperatingSystemsLab1
line 7 C/C++ Problem
implicit declaration of function 'malloc' [-Wimplicit-function-declaration] Mp3.c /OperatingSystemsLab1
line 21 C/C++ Problem
assignment makes pointer from integer without a cast [enabled by default] Mp3.c /OperatingSystemsLab1
line 8 C/C++ Problem
implicit declaration of function 'free' [-Wimplicit-function-declaration] Mp3.c /OperatingSystemsLab1
line 40 C/C++ Problem
incompatible implicit declaration of built-in function 'malloc' [enabled by default] Mp3.c /OperatingSystemsLab1
line 21 C/C++ Problem
incompatible implicit declaration of built-in function 'malloc' [enabled by default] Mp3.c /OperatingSystemsLab1
line 57 C/C++ Problem
incompatible implicit declaration of built-in function 'free' [enabled by default] Mp3.c /OperatingSystemsLab1
line 40 C/C++ Problem
私のコードは次のとおりです
#include <stdio.h>
#include "Mp3.h"
void add(struct MP3 *pointer, char artistname, char albumname, char songname, int date, int runtime){
/*make structure for new data*/
struct MP3 *data;
data->artistName = artistname;
data->albumName = albumname;
data->date=date;
data->runTime=runtime;
data->next=NULL;
data->prev=NULL;
if(pointer->next==NULL) {
pointer->next = data;
}
else {
while(pointer->next != NULL){
pointer = pointer->next;
}
pointer->next = (struct MP3*)malloc(sizeof(struct MP3));
pointer->next = data;
struct MP3 *temp = pointer;
pointer = pointer->next;
pointer->prev = temp;
}
};
void delete(struct MP3 *pointer, char *artistname){
while(pointer->next!=NULL && (pointer->next)->artistName!=artistname){
pointer = pointer->next;
}
if(pointer->next==NULL){
return;
}
struct MP3 *temp;
temp = pointer->next;
pointer->next = temp->next;
pointer->next->prev = pointer;
free(temp);
};
void print(struct MP3 *pointer){
if(pointer==NULL){
return;
}
printf("Artist name: %s \n", pointer->artistName);
printf("Album name: %s \n", pointer->albumName);
printf("Title: %s \n", pointer->songName);
printf("Date: %d \n", pointer->date);
printf("Runtime: %d\n", pointer->runTime);
print(pointer->next);
};
int main(){
struct MP3 *start,*current;
start = (struct MP3 *)malloc(sizeof(struct MP3));
current = start;
current->next = NULL;
current->prev = NULL;
printf("1. Add\n");
printf("2. Delete\n");
printf("3. Print\n");
while(1)
{
int query;
scanf("%d",&query);
if(query==1)
{
int rt,d;
char artn,albn,sn;
scanf("%c %c %c %d %d",&artn,&albn,&sn,&d,&rt);
add(start,artn,albn,sn,d,rt);
}
else if(query==2)
{
char artn;
scanf("%c",&artn);
delete(start,&artn);
}
else if(query==3)
{
printf("The list is ");
print(start->next);
printf("\n");
}
}
};
そしてヘッダーファイル
#ifndef MP3_H_
#define MP3_H_
struct MP3{
char *artistName;
char *albumName;
char *songName;
int date;
int runTime;
struct MP3 *next;
struct MP3 *prev;
};
#endif /* MP3_H_ */
私が言ったように、私は新しいので私を憐れんでください。どんな助けでもいただければ幸いです!ありがとうございました!