I would like the user to define the size of the array when the program starts, I currently have:
#define SIZE 10
typedef struct node{
int data;
struct node *next;
} node;
struct ko {
struct node *first;
struct node *last;
} ;
struct ko array[SIZE];
This works, however, I would like to remove the #define SIZE
, and let SIZE be a value that the user defines, so in the main function i have:
int SIZE;
printf("enter array size");
scanf("%d", &SIZE);
how can I get that value to the array?
EDIT: now i have the following in the .h file:
typedef struct node{
int data;
struct node *next;
} node;
struct ko {
struct node *first;
struct node *last;
} ;
struct ko *array;
int size;
and this in the main.c file:
printf("size of array: ");
scanf("%d", &size);
array = malloc(sizeof(struct ko) * size);
Should this work? It doesn't the program crashes but I don't know if the problem is here or, elsewhere in the program...