Download c source code

// Copyright 2018,2023 Jeisson Hidalgo <jeisson.hidalgo@ucr.ac.cr> CC-BY 4.0
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include "array.h"

#define MIN_CNT 10
#define MAX_CNT 20

void print_array(const char* name, const array_t array) {
  printf("%s =", name);
  for (size_t index = 0; index < array_get_count(array); ++index) {
    printf(" %zu", (size_t)array_get_element(array, index));
  }
  putchar('\n');
  fflush(stdout);
}

int main() {
  array_t array1 = array_create(MAX_CNT);
  array_t array2 = array_create(MAX_CNT);

  srand((unsigned int)((unsigned long)time(NULL) + clock()));
  const size_t count = MIN_CNT + rand() % MAX_CNT;
  for (size_t index = 0; index < count; ++index) {
    array_append(array1, (void*)(10 + (size_t)rand() % 90));
    array_append(array2, (void*)(100 + (size_t)rand() % 900));
  }

  print_array("array1", array1);
  print_array("array2", array2);

  array_destroy(array1);
  array_destroy(array2);

  return 0;
}