I wanted to add values into my. array
typedef struct teleporter {
int start;
int end;
}teleporters;
int main(int argc, char **argv) {
int lenght = 2;
teleporters *teleportPlaces;
teleporters mytele;
mytele.start = 0;
mytele.end = 0;
teleportPlaces = calloc(2, sizeof(teleporters));//malloc (sizeof(teleporters) * (lenght));
if (teleportPlaces != NULL) {
teleportPlaces = NULL;
}
for (int i = 0; i < lenght; i++) {
teleportPlaces[i] = mytele;
}
printf("Teleport END[0] = %d",teleportPlaces[0].end);
free(teleportPlaces);
return 0;
}
but everytime i add it, it gave me an segmentation error,
how do i solve this error? it'll be great if there's an article or answer about it, thanks
if (teleportPlaces != NULL) { teleportPlaces = NULL; }- what is this?2is the length.if (teleportPlaces != NULL) {