Category : C Source Code
Archive   : VARRAY.ZIP
Filename : VARTEST.C

 
Output of file : VARTEST.C contained in archive : VARRAY.ZIP
Listing Three

/* Example Program Using Virtual Arrays */

#include

/* Access Macros */

#define VREC(i) ((items *)access_v_rec(item_array,i))
#define item(i) VREC(i)->v_item
#define qty(i) VREC(i)->v_qty
#define desc(i) VREC(i)->v_desc

/* Array element structure typedef */

typedef struct {
int v_item,
v_qty;
char v_desc[24];
} items;

main()
{
VACB *item_array;
long i;

/* create a virtual array setting element size to */
/* the size of items structure and setting the */
/* initialization char to the space char */

init_v_array("ITEMS.VAR",sizeof(items),' ');

/* open the virtual array, reserve buffer space for 10 elements */

item_array = open_v_array("ITEMS.VAR",10);


/* create 50 array items */

for (i = 0; i < 50 ; i++) {
item(i) = i + 1;
qty(i) = 0;
sprintf(desc(i)," Item # %ld", i + 1);
}

/* print contents of the 50 array items */
/* plus the ascii code of last char in v_desc */

for (i = 0; i < 50; i++)
printf("Element # %ld Item = %d Qty = %d Desc = %s %d\n",
i, item(i), qty(i), desc(i), (int) desc(i)[23]);

/* close virtual array */

close_v_array(item_array);
}


  3 Responses to “Category : C Source Code
Archive   : VARRAY.ZIP
Filename : VARTEST.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/