Annotation of libaitio/example/test_array.c, revision 1.1.2.1
1.1.2.1 ! misho 1: #include <stdio.h>
! 2: #include <string.h>
! 3: #include <aitio.h>
! 4:
! 5: int
! 6: main(int argc, char **argv)
! 7: {
! 8: array_t *a = NULL;
! 9:
! 10: a = io_arrayInit(10);
! 11: if (!a) {
! 12: printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError());
! 13: return 1;
! 14: }
! 15:
! 16: switch (argc) {
! 17: case 4:
! 18: io_arraySet(a, 5, argv[3]);
! 19: case 3:
! 20: io_arraySet(a, 4, argv[2]);
! 21: case 2:
! 22: io_arraySet(a, 1, argv[1]);
! 23: }
! 24:
! 25: printf(">>> a[0]=%s a[1]=%s a[2]=%s a[3]=%s a[4]=%s a[5]=%s\n",
! 26: io_arrayGet(a, 0, char*), io_arrayGet(a, 1, char*),
! 27: io_arrayGet(a, 2, char*), io_arrayGet(a, 3, char*),
! 28: io_arrayGet(a, 4, char*), io_arrayGet(a, 5, char*));
! 29: printf(">>> last used element=%d array size=%d\n", io_arrayLen(a), io_arraySize(a));
! 30:
! 31: io_arrayVacuum(a, VACUUM_BETWEEN);
! 32: printf("vacuum:: a[0]=%s a[1]=%s a[2]=%s a[3]=%s a[4]=%s a[5]=%s\n",
! 33: io_arrayGet(a, 0, char*), io_arrayGet(a, 1, char*),
! 34: io_arrayGet(a, 2, char*), io_arrayGet(a, 3, char*),
! 35: io_arrayGet(a, 4, char*), io_arrayGet(a, 5, char*));
! 36:
! 37: printf("vacuum:: last used element=%d array size=%d\n", io_arrayLen(a), io_arraySize(a));
! 38:
! 39: io_arrayGrow(a, io_arrayLen(a) + 3);
! 40: printf("grow:: last used element=%d array size=%d\n", io_arrayLen(a), io_arraySize(a));
! 41: printf("grow:: a[0]=%s a[1]=%s a[2]=%s a[3]=%s a[4]=%s a[5]=%s\n",
! 42: io_arrayGet(a, 0, char*), io_arrayGet(a, 1, char*),
! 43: io_arrayGet(a, 2, char*), io_arrayGet(a, 3, char*),
! 44: io_arrayGet(a, 4, char*), io_arrayGet(a, 5, char*));
! 45:
! 46: io_arrayGrow(a, 1);
! 47: io_arrayGrow(a, 2);
! 48: printf("shrink:: last used element=%d array size=%d\n", io_arrayLen(a), io_arraySize(a));
! 49: printf("shrink:: a[0]=%s a[1]=%s\n", io_arrayGet(a, 0, char*), io_arrayGet(a, 1, char*));
! 50:
! 51: io_arrayDestroy(&a);
! 52: return 0;
! 53: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>