home *** CD-ROM | disk | FTP | other *** search
- /* example2.c */
-
- #include <stdio.h>
- #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);
- }
-
-