-
Notifications
You must be signed in to change notification settings - Fork 1
/
circular_buffer.c
64 lines (51 loc) · 858 Bytes
/
circular_buffer.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
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
struct ele {
char *data;
};
struct ring_buf {
int size;
int start;
int count;
struct buffer *ele;
};
struc ring_buf main_buf;
int buf_size;
void ring_init(struct ring_buf *buf, int size)
{
buf->size = size;
buf->start = 0;
buf->count = 0;
ele = (struct ele *)malloc(sizeof(struct ele), size);
}
int ring_full(struct ring_buf *buf)
{
if(buf->count == buf->size)
return 1;
else
return 0;
}
int ring_empty(struct ring_buf *buf)
{
if(!buf->count)
return 1;
else
return 0;
}
void add_to_ring(struct ring_buf *buf, char *data)
{
if(!ring_full(buf)) {
}
}
int main (void)
{
int i;
char temp_buf[BUFSIZ];
buf_size = 10;
ring_init(&main_buf, buf_size);
for(i = 0; i < size; i++) {
memset(temp_buf, 0, BUFSIZ);
sprintf(temp_buf, "string%d",i)
add_to_ring(&main_buf, temp_buf);
}
return 0;
}