title: My program stop working
body: <p>Well, this one exercise that I need to do, but im stuck at this point, where I try to register a new album in my program and when I will select one Artist it stop working.</p>
  
  <p>Anyone knows why my program is crashing? I do not have any errors in console/debug/compiling.</p>
  
  <p>funcoes.c</p>
  
  <pre><code>    #include &lt;stdio.h&gt;
      #include &lt;stdlib.h&gt;
      #include &lt;string.h&gt;
      #include &lt;ctype.h&gt;
      #include "funcoes.h"
  
      void mostraMenu( void )
      {
          printf("\n\nChoose one \n 1 - Register Artist \n 2 - Register Music \n 3 - Register Album \n 4 - List Music \n 5 - List Artist\n 0 - Exit \n");
      }
  
      void cadastrarArtista( Artista **vetArt , int nArt)
      {
  
          Artista *tmp;
          tmp = (Artista*)malloc( sizeof( Artista ) );
          setbuf(stdin, NULL);
          printf("Informe o nome do artista:\t");
          scanf("%[^\n]s", tmp-&gt;nome);
          setbuf(stdin, NULL);
  
          printf("Informe a nacionalidade:\t");
          scanf("%[^\n]s", tmp-&gt;nacionalidade);
          setbuf(stdin, NULL);
  
          vetArt[nArt] = tmp;
      }
  
      void cadastrarMusica( Musica **vetMus , int nMus)
      {
  
          Musica *tmp;
          tmp = (Musica*)malloc( sizeof( Musica ) );
          setbuf(stdin, NULL);
          printf("Informe o nome da musica:\t");
          scanf("%[^\n]s", tmp-&gt;nome);
          setbuf(stdin, NULL);
  
          printf("Informe o ano:\t");
          scanf("%d", &amp;tmp-&gt;ano);
          setbuf(stdin, NULL);
  
          vetMus[nMus] = tmp;
      }
  
      void cadastrarAlbum (Album *vetAlbum, Musica **vetMusica, int tamanhoMusicas, Artista **vetArtistas, int tamanhoArtistas)
      {
          Album albumAux;
          vetAlbum-&gt;musicas =(Musica**) malloc(sizeof(Musica *));
          vetAlbum-&gt;artistas = (Artista**) malloc(sizeof(Artista *));
  
          int numArtAlb, numMusAlb, i,a = 0;
          char _nome[TAM_NOME] , _musica[TAM_NOME];
          if( tamanhoArtistas == 0 || tamanhoMusicas == 0 )
          {
              printf("There is not at least one artist/music");
              return;
          }
  
          printf("\tName of the album:\t");
          setbuf(stdin, NULL);
          scanf("%[^\n]s", vetAlbum-&gt;nome);
          setbuf(stdin, NULL);
          printf("\tYear of the album:\t");
          scanf("%d", &amp;vetAlbum-&gt;ano);
          setbuf(stdin, NULL);
  
          while(a != 3)
          {
              start:
              printf("\t1 - Associate an Artist with album \n\t2 - Associate music with album\n\t3 - Parar\n");
              scanf("%d", &amp;a);
              switch(a)
              {
                  case 1:
  
                      printf("\tArtist Name:\t");
                      setbuf(stdin, NULL);
                      scanf("%[^\n]s", _nome);
                      setbuf(stdin, NULL);
  
                      for(i = 0; i &lt; tamanhoArtistas; i++)
                      {
                          if ( strcmp(vetArtistas[i]-&gt;nome, _nome) == 0 )
                          {
                              printf("\tArtist Found!\n");
                              vetAlbum-&gt;artistas[numArtAlb] = vetArtistas[i];
                              numArtAlb += 1;
  
                              vetAlbum-&gt;num_artistas = numArtAlb;
                              albumAux.artistas = (Artista**)malloc((numArtAlb +1)*sizeof(Artista*));
  
                              if ( albumAux.artistas != NULL )
                              {
                                  vetAlbum-&gt;artistas = albumAux.artistas;
                              }
                              break;
                          }
                          else if( strcmp (vetArtistas[i]-&gt;nome, _nome) != 0 &amp;&amp; i == tamanhoArtistas-1)
                          {
                              printf("\tThis Artist does not exist!\n");
                              goto start;
                          }
                      }
                      break;
                      //FIM FOR
  
                  case 2:
                      printf("\tName of the music:\t");
                      setbuf(stdin, NULL);
                      scanf("%[^\n]s", _musica);
                      setbuf(stdin, NULL);
  
                      for(i = 0; i &lt; tamanhoMusicas; i++)
                      {
                          if ( strcmp(vetMusica[i]-&gt;nome, _nome) == 0 )
                          {
                              printf("\tMusic Found!\n");
                              vetAlbum-&gt;musicas[numMusAlb] = vetMusica[i];
                              numMusAlb += 1;
  
                              vetAlbum-&gt;num_musicas = numMusAlb;
                              albumAux.musicas = (Musica**)malloc((numMusAlb +1)*sizeof(Musica*));
  
                              if ( albumAux.musicas != NULL )
                              {
                                  vetAlbum-&gt;musicas = albumAux.musicas;
                              }
                              break;
                          }
                          else if( strcmp (vetMusica[i]-&gt;nome, _musica) != 0 &amp;&amp; i == tamanhoMusicas-1)
                          {
                              printf("\tMusic not found!\n");
                              goto start;
                          }
                      }
                      break;
  
                  case 3:
  
                      if(numArtAlb == 0 || numMusAlb == 0){
                          printf("\tOne album need at least one music/artist!\n");
                          goto start;
                      }else{
                          break;
                      }
  
                  default:
  
                      printf("Invalid Option\n");
                      break;
              }
              //FIM SWITCH
  
          }
          //FIM WHILE
      }
  //FIM FUNCAO
  </code></pre>
  
  <p>funcoes.h    </p>
  
  <pre><code>#ifndef funcoes_h
  #define funcoes_h
  
  /* Definição do tamanho máximo de um nome */
  #define TAM_NOME 80
  
  typedef struct {
      char nome[TAM_NOME];
      int ano;
  } Musica;
  
  typedef struct {
      char nome[TAM_NOME];
      char nacionalidade[TAM_NOME];
  } Artista;
  
  typedef struct {
      char nome[TAM_NOME];
      int ano;
      Musica **musicas;
      int num_musicas;
      Artista **artistas;
      int num_artistas;
  } Album;
  
  void mostraMenu( void );
  void cadastrarArtista(Artista **vetArt, int nArt);
  void cadastrarMusica(Musica **vetMus, int nMus);
  void cadastrarAlbum(Album *vetAlbum, Musica **vetMusica, int tamanhoMusicas, Artista **vetArtistas, int tamanhoArtistas);
  #endif
  </code></pre>
  
  <p>main.c</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include "funcoes.h"
  int main ( void )
  {
   Artista **vetArt = (Artista**)malloc(sizeof(Artista*));
   Musica **vetMus = (Musica**)malloc(sizeof(Musica*));
   Album *vetAlbum = (Album*)malloc(sizeof(Album));
  
   int nArt = 0;
   int nMus = 0;
   int nAlb = 0;
   int opcao;
   int op = 0;
  
  while( op == 0)
  {
       mostraMenu();
       scanf("%d",&amp;opcao);
       if ( opcao == 0 )
       {
           op = 1;
           break;
       }
       else if (opcao == 1)
       {
          Artista **artAux = (Artista**)malloc((nArt+1)*sizeof( Artista* ) );
          if (artAux == NULL)
          {
              printf( "Alocacao invalida.");
              exit(EXIT_FAILURE);
          }
          free(artAux);
          cadastrarArtista( vetArt , nArt );
          nArt += 1;
  
       }else if (opcao == 2)
       {
          Musica **musAux = (Musica**)malloc((nMus+1)*sizeof( Musica* ) );
          if (musAux == NULL)
          {
              printf( "Alocacao invalida.");
              exit(EXIT_FAILURE);
          }
          free(musAux);
          cadastrarMusica( vetMus , nMus );
          nMus += 1;
  
       }else if (opcao == 3)
       {
          cadastrarAlbum(vetAlbum, vetMus, nMus, vetArt, nArt);
          nAlb += 1;
       }
  }
   return 0;
  }
  </code></pre>