-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer_example.c
More file actions
44 lines (35 loc) · 920 Bytes
/
buffer_example.c
File metadata and controls
44 lines (35 loc) · 920 Bytes
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
/*
* File: buffer_example.c
* Author: Mike Curry
* License: The MIT License (MIT)
*
* Created on February 27, 2015, 12:48 PM
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "buffer.h"
int main() {
buffer_data *buff;
buff = buffer_init(10);
// proceed only if we have a valid buffer...
if (buff != NULL) {
ssize_t rtval = 0;
int i;
// original string
for (i = 1; i < 100; ++i) {
fprintf(stdout, "String: -->|%s|<--\n\n", buff->content);
rtval = buffer_append(buff, "ABCDEFGH");
if (rtval < 1) {
fprintf(stderr, "Error appending, stopping!\n");
exit(1);
} else {
fprintf(stdout, "appended %zd\n", rtval);
}
}
}
// free the buffer
buffer_destroy(buff);
return 0;
}