Create a linked list structure Music that contains the data fields Name, Artist,
ID: 3541037 • Letter: C
Question
Create a linked list structure Music that contains the data fields Name, Artist, Number_of_Songs, and a pointer to the list. Create the structure with 3 members and fill in data for each member. Create a function that will display() all the data for each member and call it from the main program.
I saw the other answer to this but it is not compiling, i get
1>------ Build started: Project: final2, Configuration: Debug Win32 ------
1> stdafx.cpp
1> AssemblyInfo.cpp
1> final2.cpp
1>final2.cpp(30): error C2440: '=' : cannot convert from 'item *' to 'list *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>final2.cpp(39): error C2440: '=' : cannot convert from 'list *' to 'item *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Explanation / Answer
please rate - thanks
your code corrected
I think you should you gets for the name so you can have a space-but didn't change it since wasn't sure
#include <conio.h>
struct Music {
char artist[30];
int no_of_songs;
struct Music *next;
};
typedef struct Music item;
int main() {
//item * curr, * head;
struct Music *head, *curr;
int i;
char arti[30];
int k;
head = NULL;
for(i=1;i<4;i++) {
curr = (item *)malloc(sizeof(item));
printf(" Enter Artsit name ");
scanf("%s",arti);
strcpy(curr->artist,arti);
printf(" Enter no of Songs ");
scanf("%d",&k);
curr->no_of_songs = k;
curr->next = head;
head = curr;
}
curr = head;
while(curr)
{
printf("Artist Name: %s No of songs :%d ",curr->artist,curr->no_of_songs);
curr = curr->next ;
}
getch();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.