Hi i have a struct array which has a char * property. However, when i try to assign multiple values to each element, when i go to read only the last value that i have written shows in all of the elements. Somehow, all char* properties have the same memory adress.
#include <stdio.h>
#include <string.h>
struct Identity{
    char *name;
    int idNumber;
} identities[5];
int main(){
    int i;
    char tempName[20];
    for(i = 0; i < 2; i++){
        printf("IDENTITY %d\n", i+1);
        printf("Name: ");
        fgets(tempName, 20, stdin);
        strtok(tempName, "\n");
        identities[i].name = tempName;
        printf("Id: ");
        scanf("%d", &identities[i].idNumber);
        getchar();
    }
    for(int i = 0; i < 5; i++){
        printf("MEMORY %d: %ld\n", i+1, identities[i].name); // FILLED VALUES HAVE EQUAL MEMORY ADRESS???? WHY??
    }
    printf("***OUTPUT***\n");
    for(i = 0; i < 5; i++){
        printf("IDENTITY %d\n", i+1);
        printf("Name: %s\n", identities[i].name);
        printf("Id: %d", identities[i].idNumber);
        if(i != 4){
            printf("\n");
        }
    }
    return 0;
}
 
    