-
Notifications
You must be signed in to change notification settings - Fork 0
/
test3.c
42 lines (32 loc) · 988 Bytes
/
test3.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <stdlib.h>
#include "array.h"
/* This program will fill an array of integers of size 100 with the first
* 20 digits of the Fibonacci series.
* It then tries to retrieve an item at position 20, which should generate
* an error.
*/
#define CAPACITY 100 // total capacity of the array
#define NEL 20 // number of elements of the series to include
int main( int argc, char **argv )
{
int data1=1, data2=1, tmp, i;
struct Performance *perf;
struct Array *array;
perf = newPerformance();
array = newArray( perf, sizeof( int ), CAPACITY );
for (i=0;i<NEL;i++)
{
writeItem( perf, array, array->nel, &data1 );
tmp = data2;
data2 = data1+data2;
data1 = tmp;
}
readItem( perf, array, 20, &data1 );
freeArray( perf, array );
printf( "reads: %5d\n", perf->reads );
printf( "writes: %5d\n", perf->writes );
printf( "mallocs: %5d\n", perf->mallocs );
printf( "frees: %5d\n", perf->frees );
free( perf );
}