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