Guest User

Untitled

a guest
Aug 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. typedef struct{
  4. char* artiest;
  5. char* titel;
  6. int jaartal;
  7. float duur;
  8. } SONG;
  9.  
  10. typedef struct{
  11. char* eigenaar;
  12. SONG* album;
  13. } COLLECTIE;
  14.  
  15. int leesGegevens(COLLECTIE*);
  16. void toonCollectie(COLLECTIE, int);
  17. void freeMemory(COLLECTIE, int);
  18.  
  19. int main(int argc, char **argv)
  20. {
  21. int aantal;
  22. COLLECTIE collectie;
  23. aantal = leesGegevens(&collectie);
  24. toonCollectie(collectie, aantal);
  25. //freeMemory(collectie, aantal);
  26. return 0;
  27. }
  28.  
  29. int leesGegevens(COLLECTIE* collectie){
  30. printf("Wat is de naam van de eigenaar\n");
  31. char naam[40];
  32. gets(naam);
  33. collectie->eigenaar = malloc(strlen(naam) * sizeof(char));
  34. strcpy(collectie->eigenaar, naam);
  35. fflush(stdin);
  36. int aantal;
  37. printf("Hoeveel songs wilt u in de lijst\n");
  38. scanf("%d", &aantal);
  39. fflush(stdin);
  40. int i;
  41. for(i = 0; i < aantal; i++){
  42. SONG* song = malloc(sizeof(SONG));
  43. printf("Song %d: \n", i +1);
  44. printf("\tartiest: ");
  45. char artiest[20];
  46. gets(artiest);
  47. fflush(stdin);
  48. (song+i)->artiest = malloc(sizeof(char) * strlen(artiest));
  49. strcpy((song+i)->artiest, artiest);
  50.  
  51. printf("\ttitel: ");
  52. char titel[20];
  53. gets(titel);
  54. fflush(stdin);
  55. (song+i)->titel = malloc(sizeof(char) * strlen(titel));
  56. strcpy((song+i)->titel, titel);
  57.  
  58. printf("\tjaartal: ");
  59. int jaartal;
  60. scanf("%d", &jaartal);
  61. (song+i)->jaartal = jaartal;
  62. fflush(stdin);
  63.  
  64. printf("\tduur: ");
  65. float duur;
  66. scanf("%f", &duur);
  67. (song+i)->duur = duur;
  68. fflush(stdin);
  69. }
  70. return aantal;
  71. }
  72.  
  73. void toonCollectie(COLLECTIE collectie, int aantal){
  74. printf("Collectie van %s\n", collectie.eigenaar);
  75. printf("%-20s%-20s%s %s \n", "artiest", "titel", "jaar", "duur");
  76. int i;
  77. for(i = 0; i< 40; i++){
  78. printf("-");
  79. }
  80. //for(i = 0; i<aantal; i++){
  81. printf("%s", collectie.album->artiest);
  82. //printf("%-20s", collectie.album->titel);
  83. //printf("%d", collectie.album->jaartal);
  84. //printf("%s", collectie.album->duur);
  85. //}
  86. }
Add Comment
Please, Sign In to add comment