I need to use a linked list in order to create a playlist of songs but when running the code it only takes my input but does not execute Song_Print
function so I don't even know if the values entered were taken. When putting all the code in 1 c file it works but not in this modular form which I need it to be.
In song.h
header file I have:
#ifndef SONG_H
#define SONG_H
struct song {
char name[50];
char artist[50];
int duration;
char genre[50];
struct song* next_song;
int ID_in_playlist;
};
void Song_New (void);
void Song_Print (void);
void init(void);
#endif
In song.c
I have:
#include <stdio.h>
#include <stdlib.h>
#include "song.h"
struct song *song = NULL;
void Song_New (void){
printf("Type in your song name: ");
scanf("%s", &song->name);
printf("Type in your artist name: ");
scanf("%s", &song->artist);
printf("Type in your song duration (in seconds): ");
scanf("%d", &song->duration);
printf("Type in your song genre: ");
scanf("%s", &song->genre);
return;
}
void Song_Print(void){
printf("-----PRINTING YOUR SONG-----\n");
printf("The song name: %s\n", song -> name);
printf("The song artist: %s\n", song -> artist);
printf("The song duration: %i\n", song -> duration);
printf("The song genre: %s\n", song -> genre);
return;
}
void init(void) {
song = (struct song *)malloc(sizeof(struct song));
return;
}
In main.c
file I have:
#include <stdio.h>
#include <stdlib.h>
#include "song.h"
int main (void){
init();
Song_New();
Song_Print();
return 0;
}