Skip to content
Snippets Groups Projects
cds.c 2.4 KiB
Newer Older
T.Wadi's avatar
T.Wadi committed
#include <stdio.h>
#include <stdlib.h>
#include "datastructure.h"
#include "cds.h"
#include "tools.h"
#include "datetime.h"

int countCDs = 0;
sCD CDData[MAXCDS];

void createCD()
{

    if (countCDs == MAXCDS)
    {
        puts("Maximum number of cds reached!");
        exit(0);
    }

    clearScreen();
    puts("Erfassung einer neuen CD");
    printLine('=', 50);

    (CDData + countCDs)->numberOfSongs = 0;
    getText("Geben Sie bitte den Titel der CD ein:", 35, &(CDData + countCDs)->title, 0);
    getText("Geben Sie bitte den Interpreten ein:", 35, &(CDData + countCDs)->artist, 1);
    getNumber("Geben Sie bitte das Erscheinungsjahr ein:", &(CDData + countCDs)->publicationYear, 1982, 2022);
    puts("Geben Sie bitte die Daten der Lieder ein:");
    creatSong();
    countCDs++;
}
void creatSong()
{

    do
    {

        printf("Lied %i:\n", ((CDData + countCDs)->numberOfSongs) + 1);
        getText("Geben Sie bitte den Titel des Liedes ein:", 35, &(CDData + countCDs)->Songs[(CDData + countCDs)->numberOfSongs].title, 0);
        getText("Geben Sie bitte den Interpreten ein:", 35, &(CDData + countCDs)->Songs[(CDData + countCDs)->numberOfSongs].artist, 1);
        inputTime("Geben Sie bitte die Dauer des Liedes ein\n   (Format hh:mm:ss oder mm:ss):\n   -> ", &(CDData + countCDs)->Songs[(CDData + countCDs)->numberOfSongs].duration);
        (CDData + countCDs)->numberOfSongs++;

    } while ((askYesOrNo("Moechten Sie noch ein weiteres Lied eingeben (j/n)?")) && ((CDData + countCDs)->numberOfSongs) < MAXSONGS);
}

void editCd()
{

    puts("editCd");
    waitForEnter();
}

void deleteCD()
{
    puts("deleteCd");
    waitForEnter();
}

void searchSong()
{
    puts("deleteCd");
    waitForEnter();
}

void sortCDs()
{
    puts("SortCd");
    waitForEnter();
}
void ListCDs()
{
    for (int i = 0; i < countCDs; i++)
    {
        putchar('\n');
        printf("Titel              : %s\n", (CDData + i)->title);
        printf("Erscheinungsjahr   : %i\n", (CDData + i)->publicationYear);
        printf("Anzahl Lieder      : %i\n", (CDData + i)->numberOfSongs);
        puts("Lieder");
        for (int j = 0; j < (CDData + i)->numberOfSongs; j++)
        {
            listOneSong(i, j);
        }
    }

    waitForEnter();
}
void listOneSong(int i, int j)
{
    printf("%.1i. %s (%s; ", (j + 1), (CDData + i)->Songs[j].title, (CDData + i)->Songs[j].artist);
    printTime((CDData + i)->Songs[j].duration, 1);
    puts(")");
}