Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have an SD card which I filled with 15 mp3 tracks and a text file that has 15 words and 15 tracks names. My question is regarding initializing the following

char* words[ ]
char* tracks [ ]

When I initialize them as [100] and [100], the listing of the dB doesn't work as I currently only have 15 tracks and words. I want code to have the ability to place 999.

So my question is: can I make both them variable arrays and how?

I tried leaving between the brackets empty and several other methods but they didn't work. So I wondering if anyone here have any other suggestions.

share|improve this question
 
Use dynamic memory allocations, malloc and then realloc? –  Alok Save 2 days ago
 
I tried using malloc but it didn't work, however will try to use realloc, thanks for your fast reply :D –  user3133400 2 days ago
 
Note char*words[] is an array of pointers! You will need buffer for string data also char[][]. As this is all dynamic, you better not use static arrays, but use some new keywords. –  LS_dev yesterday
add comment

1 Answer

Arduino code is compiled as C++; you can use the new char[size] and delete[] operators.

share|improve this answer
 
I tried what still i didnt get anything but when i tried using: //words = (char** )calloc(track_size++,sizeof(char*)); //tracks = (char** )calloc(track_size++,sizeof(char*)); with delete []; it only outputs the last word and last track, i dont understand why?? –  user3133400 2 days ago
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.