fork download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. struct track_ {
  5. char *tracks_title;
  6. int playlist_hits;
  7. };
  8. typedef struct track_ track;
  9.  
  10. struct album_ {
  11. int num_tracks;
  12. struct track_* tracks;
  13. };
  14. typedef struct album_ album;
  15.  
  16.  
  17. const int max_number_of_album = 100;
  18. int number_of_albums = 0;
  19.  
  20. album *all_albums_p = NULL;
  21.  
  22. void init_all_albums();
  23. void done_all_albums();
  24. album* append_album(int num_tracks);
  25. void cleanup_album(album* a);
  26.  
  27. void init_all_albums()
  28. {
  29. if (!all_albums_p)
  30. all_albums_p = (album *) malloc(sizeof(album)*max_number_of_album);
  31. }
  32.  
  33. void done_all_albums()
  34. {
  35. if (all_albums_p)
  36. {
  37. while (number_of_albums--)
  38. cleanup_album(&all_albums_p[number_of_albums]);
  39.  
  40. free(all_albums_p);
  41. all_albums_p = NULL;
  42. }
  43. }
  44.  
  45. album* append_album(int num_tracks)
  46. {
  47. if (number_of_albums >= max_number_of_album)
  48. return NULL;
  49.  
  50. int index = number_of_albums++;
  51. all_albums_p[index].num_tracks = num_tracks;
  52. all_albums_p[index].tracks = (track*) malloc(sizeof(track)*num_tracks);
  53.  
  54. return all_albums_p+index;
  55. }
  56.  
  57. void cleanup_album(album* a)
  58. {
  59. if (a)
  60. {
  61. while (a->num_tracks--)
  62. free_track(a->tracks[a->num_tracks]);
  63.  
  64. free(a->tracks);
  65. }
  66. }
  67.  
  68. // free_track left as an exercise for the reader
  69.  
  70. int main(int argc, const char *argv[])
  71. {
  72.  
  73. return 0;
  74. }
  75.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘cleanup_album’:
prog.c:62: warning: implicit declaration of function ‘free_track’
/home/ch5tTB/cclmnAVV.o: In function `cleanup_album':
prog.c:(.text+0x43): undefined reference to `free_track'
collect2: ld returned 1 exit status
stdout
Standard output is empty