Skip to content

Instantly share code, notes, and snippets.

@confususs
Last active August 29, 2015 13:56
Show Gist options
  • Save confususs/8831062 to your computer and use it in GitHub Desktop.
Save confususs/8831062 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#ifndef TYPEDEF_ENUM_BOOLEAN_DECLARED_
#define TYPEDEF_ENUM_BOOLEAN_DECLARED_
typedef enum{ false, true } boolean;
char* bool_print[] = {"no", "yes"};
#endif
#ifndef BOOL_PRINT_DECLARED_
#define BOOL_PRINT_DECLARED_
#define BOOL_FMT(bool_expr) "%s", (bool_expr) ? "true" : "false"
#endif
typedef struct song song;
typedef struct artist artist;
typedef struct playlist playlist;
struct song {
short id; /* unique identity of the song */
char name[30]; /* name of song */
int duration; /* duration in seconds */
artist* artist; /* pointer to artist */
song* next; /* pointer to next song of the same artist */
};
struct artist {
short id; /* unique identity of artist */
char name[30]; /* name of artist (could be a band as well) */
song* songList; /* pointer to linked list containing all songs from this artist */
};
struct playlist {
short id; /* unique identity of playlist */
song** songs; /* all songs in this playlist */
short numberOfSongs; /* numberOfSongs in this playlist */
};
/* function prototypes */
artist** input_artist_info ( artist** artist_ptr , int* numberOfArtists){
// how long is the string read
char str[60];
// for printing integers
char print_integer[5];
// where student 'database' is.
char* file_to_open="artists.txt";
int i;
FILE *fp;
fp = fopen (file_to_open, "r"); //open in read mode
if (fp == NULL){
printf("\nError, Unable to open the file for reading\n");
}
//artist* artist_list = calloc(15, sizeof(artist)); mark had dit verzonnen
struct artist *artist_list;
artist_list=(struct artist*)malloc(sizeof(struct artist));
while(fgets(str, sizeof(str), fp) != NULL && str[0]!='\n')
{
int artist_id;
char artist_name[30];
//puts(str);
sscanf(str, "%i %[^\t\n]", &artist_id, artist_name);
//puts(artist_id);
//printf("%c\n",*artist_name);
//printf(artist_id);
printf("%i", artist_id);
printf("\n");
printf(artist_name);
printf("\n");
artist_list[i].id = artist_id;
strcpy(artist_list[i].name, artist_name);
//(artist_list+i)->id = artist_id;
//(artist_list+i)->name = artist_name;
i++;
}
fclose(fp);
}
/* at start and exit: numberOfArtists indicates about how many artists info is stored */
/* artist_ptr is the variable used to access info about all the artist */
struct artist *a = NULL;
struct song *s = NULL;
struct playlist *p = NULL;
artist* find_artist( artist** artist_ptr , int id){
}
/* id indicates the artists id that needs to be found */
/* artist_ptr is the variable used to access info about all the artist */
boolean input_song_info ( song** song_ptr );
/* song_ptr is the variable used to access info about all the songs */
playlist** compose_playlist ( playlist** playlist_ptr , int* numberOfPlaylists);
/* at start and exit: numberOfPlaylists indicates the number of playlists stored */
/* playlist_ptr is the variable used to access info about all the playlists */
void playlist_stats ( playlist* playlist_ptr , int numberOfPlaylists);
/* numberOfPlaylists indicates the number of playlists stored */
/* playlist_ptr is the variable used to access info about all the playlists */
int main(int argc, char *argv[]){
int numberOfArtists = 0;
int numberOfSongs = 0;
int numberOfPlaylists = 0;
input_artist_info(&a, &numberOfArtists);
scanf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment