how to play multi songs from sd card module

Hi!
I try to write a code for reading song names (.wav) from sd card (from root directory) and stored this songs in an array,but I don’t know how ! :frowning: :frowning:
This is what I wrote

#include <SPI.h>
#include <SD.h>
#include <TMRpcm.h>
#include <IRremote.h>
#define array_size 33
#define RECV_PIN 8
TMRpcm sound;
IRrecv irrecv(RECV_PIN);
decode_results results;
File root;
int music_index = 0;
char *resultsArray[array_size];
//char wavb[array_size];
void setup() {
  Serial.begin(9600);
  sound.speakerPin = 9;
  irrecv.enableIRIn();
  if (!SD.begin()) {
    Serial.println("initialization failed!");
    while (1);
  }
  root = SD.open("/");
  while (true) {
    File entry = root.openNextFile();
    if (!entry) {
      break;
    }
    if (strstr(entry.name(), ".WAV"))
    {
      resultsArray[music_index] = (char *)malloc (strlen(entry.name()));
      strncpy (resultsArray[music_index], entry.name(), strlen(entry.name()));
      music_index++;
      Serial.print(music_index, DEC);
      Serial.print("-  ");
      Serial.println(entry.name());
    }
  }
}
void loop() {
  sound.play(resultsArray[0]);
}

Can you help me , please?!
Thank you.

Your malloc is one character too short - you need to allow a byte for the terminating zero.

wildbill:
Your malloc is one character too short - you need to allow a byte for the terminating zero.

Do you mean I need to add the zero of end of string?

No. strcpy does that for you. You just need to allocate sufficient space.