Q:

How to create a new array but use the same variable in C?

The reason why I am stuck on this is because of how C handles arrays, which is through pointers which I am new at. This is my case(not exactly my problem but a simplistic case):
char *keywords[k_num_of_keywords];
for(int i = 0; i < k_num_of_keywords; i++) {
    char temp[] = "float";
    keywords[i] = temp;
}

In this case, it would put float in all the indexes, but more importantly, the same address of wherever the string "float" is located. My case is slightly different, because I want to automate initializing a new char array for each index, but still use the same variable, rather than the same address in each index. How can I accomplish this in a for loop?

A:

You should allocate memory for every element for "keywords", for example:
char *keywords[k_num_of_keywords];
for(int i = 0; i < k_num_of_keywords; i++) {
    char temp[] = "float";
    int len = strlen(temp);
    keywords[i] = (char *)malloc(sizeof(char) * (len + 1));
    memcpy(keywords[i], temp, len + 1);
}

