forked from aquini/alpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alpt-a.c
51 lines (42 loc) · 851 Bytes
/
alpt-a.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
42
43
44
45
46
47
48
49
50
51
/*
* alpt-a.c - a little programming test
* fix all bugs you find out on this code in order to make it run smoothly
* and return 0 when it finishes.
*/
#include <stdio.h>
#include <stdlib.h>
#define MAX_ITEMS 10
#define MAX_BLKSZ 64
char *blockptr;
static inline void blocks_alloc_and_init(void)
{
int i, j;
for (i = 0; i < MAX_ITEMS; i++) {
blockptr = malloc(MAX_BLKSZ);
for (j = 0; j < MAX_BLKSZ; j++)
blockptr[j] = 1;
}
}
static inline void blocks_print_usage(void)
{
int i, j;
for (i = 0; i < MAX_ITEMS; i++) {
printf("blk %d: ", i);
for (j = 0; j < MAX_BLKSZ; j++)
printf("%d", blockptr[j]);
printf("\n");
}
}
static inline void blocks_release(void)
{
int i;
for (i = 0; i < MAX_ITEMS; i++)
free(blockptr);
}
int main(void)
{
blocks_alloc_and_init();
blocks_print_usage();
blocks_release();
return 0;
}