Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- typedef struct{
- char* artiest;
- char* titel;
- int jaartal;
- float duur;
- } SONG;
- typedef struct{
- char* eigenaar;
- SONG* album;
- } COLLECTIE;
- int leesGegevens(COLLECTIE*);
- void toonCollectie(COLLECTIE, int);
- void freeMemory(COLLECTIE, int);
- int main(int argc, char **argv)
- {
- int aantal;
- COLLECTIE collectie;
- aantal = leesGegevens(&collectie);
- toonCollectie(collectie, aantal);
- //freeMemory(collectie, aantal);
- return 0;
- }
- int leesGegevens(COLLECTIE* collectie){
- printf("Wat is de naam van de eigenaar\n");
- char naam[40];
- gets(naam);
- collectie->eigenaar = malloc(strlen(naam) * sizeof(char));
- strcpy(collectie->eigenaar, naam);
- fflush(stdin);
- int aantal;
- printf("Hoeveel songs wilt u in de lijst\n");
- scanf("%d", &aantal);
- fflush(stdin);
- int i;
- for(i = 0; i < aantal; i++){
- SONG* song = malloc(sizeof(SONG));
- printf("Song %d: \n", i +1);
- printf("\tartiest: ");
- char artiest[20];
- gets(artiest);
- fflush(stdin);
- (song+i)->artiest = malloc(sizeof(char) * strlen(artiest));
- strcpy((song+i)->artiest, artiest);
- printf("\ttitel: ");
- char titel[20];
- gets(titel);
- fflush(stdin);
- (song+i)->titel = malloc(sizeof(char) * strlen(titel));
- strcpy((song+i)->titel, titel);
- printf("\tjaartal: ");
- int jaartal;
- scanf("%d", &jaartal);
- (song+i)->jaartal = jaartal;
- fflush(stdin);
- printf("\tduur: ");
- float duur;
- scanf("%f", &duur);
- (song+i)->duur = duur;
- fflush(stdin);
- }
- return aantal;
- }
- void toonCollectie(COLLECTIE collectie, int aantal){
- printf("Collectie van %s\n", collectie.eigenaar);
- printf("%-20s%-20s%s %s \n", "artiest", "titel", "jaar", "duur");
- int i;
- for(i = 0; i< 40; i++){
- printf("-");
- }
- //for(i = 0; i<aantal; i++){
- printf("%s", collectie.album->artiest);
- //printf("%-20s", collectie.album->titel);
- //printf("%d", collectie.album->jaartal);
- //printf("%s", collectie.album->duur);
- //}
- }
Add Comment
Please, Sign In to add comment