So basically the program runs fine if I call array_print(array);
from main. But when I call array_print(array);
from edit.c the program crashes!
array.c
struct array* array_create()
{
struct array* array = (struct array*) malloc(sizeof(struct array));
array->data = (int*) malloc(sizeof(int) * 10000);
array->size = 10000;
return array;
}
void array_print(ARRAY array)
{
int i;
for (i = 0; i < array->size; i++)
printf("%d ", array->data[i]);
}
array.h
struct array {
int* data;
int size;
};
typedef struct array* ARRAY;
ARRAY array_create();
void array_print(ARRAY array);
edit.c
ARRAY array; // Which array is which?! I have one array in main too...
void edit()
{
array_print(array);
}
main.c
ARRAY array;
array = array_create();
edit(); // This makes the program crash
EDIT What does this mean in edit.c? When does the array become NULL? And what is calling the code in edit.c, nothing?!:
ARRAY array = NULL; // When is this being called and why? I don't want to reset it, I want to work with the array in main...
void edit()
{
array_print(array);
}