Category : C Source Code
Archive   : XXALLOC.ZIP
Filename : EXAMPLE2.C

 
Output of file : EXAMPLE2.C contained in archive : XXALLOC.ZIP
/* example2.c */

#include
#include "xxalloc.h"

typedef struct
{
double dnum;
int inum;
} NUM;

/* structure initialization function */
/* passed as an argument to {d}n_init() */
void num_init(num)
NUM *num;
{
num->dnum = 1.0;
num->inum = 1;
return;
}

/* structure printing function */
/* passed as an argument to {d}n_prnt() */
void num_prnt(fp, num)
FILE *fp;
NUM *num;
{
fprintf(fp, "%5.1f %3d ", num->dnum, num->inum);
return;
}

main()
{
int i;
NUM *num;

/* allocate a one dimensional array of NUM */

num = (NUM *) n1_alloc(0, 4, sizeof(NUM));

/* initialize the array to 1.0 and print */

n1_init(num, 0, 4, sizeof(NUM), num_init);
printf("\ninitialized to 1\n");
n1_prnt(stdout, num_prnt, num, 0, 4, sizeof(NUM));

/* set the array equal to the i and print */

for (i = 0; i <= 4; i++)
{
num[i].dnum = (double) i;
num[i].inum = i;
}
printf("\nset to i\n");
n1_prnt(stdout, num_prnt, num, 0, 4, sizeof(NUM));

/* renumber the indices a la FORTRAN and print */
/* the new indices must be used from now on */

num = (NUM *) n1_renum(num, 0, 4, 1, 5, sizeof(NUM));
printf("\nindicies renumbered\n");
n1_prnt(stdout, num_prnt, num, 1, 5, sizeof(NUM));
printf("\n");

/* free the allocated memory */

n1_free(num, 1, 5, sizeof(NUM));
exit(0);
}



  3 Responses to “Category : C Source Code
Archive   : XXALLOC.ZIP
Filename : EXAMPLE2.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/