I am new to C and I want to create a dynamic array to store strings. I wrote the code below for it but it didn't work. Array elements contain some ASCII chars instead of string.
I want historyArray[0] value to be "foo". How can I do that?
typedef struct {
    char *historyCommand;
    int usedSize;
    int maximumSize;
} HistoryArray;
void CreateHistoryArray(HistoryArray *HistoryArray) {
    HistoryArray->historyCommand = (char *) malloc(sizeof(char) * MAX_LEN);
    HistoryArray->usedSize = 0;
    HistoryArray->maximumSize = INITIAL_SIZE;
}
void ExpandHistoryArray(HistoryArray *HistoryArray, int newSize) {
    int *newArray = (char *) malloc(sizeof(char) * newSize);
    memcpy(newArray, HistoryArray->historyCommand, sizeof(char) * HistoryArray->maximumSize);
    free(HistoryArray->historyCommand);
    HistoryArray->historyCommand = newArray;
    HistoryArray->maximumSize = newSize;
}
void AddHistoryValue(HistoryArray *HistoryArray, char historyCommand[]) {
    strcpy(HistoryArray->historyCommand[HistoryArray->usedSize], historyCommand);
    HistoryArray->usedSize++;
    if (HistoryArray->usedSize == HistoryArray->maximumSize) {
        ExpandHistoryArray(HistoryArray, HistoryArray->maximumSize * 2);
    }
}
void freeHistoryArray(HistoryArray *a) {
    free(a->historyCommand);
    a->historyCommand = NULL;
    a->usedSize = 0;
    a->maximumSize = 2;
}
HistoryArray historyArray;

historyArray[0]is not achararray. Please be more precise in your description. And please format your code with proper indentation to make it readable.char *HistoryArrayis not an array of strings, it's an array of characters, which is just a single string.BTW,malloc + memcpy + freeis the same asrealloc.strcpy()line?