-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtac_typed.c
More file actions
36 lines (33 loc) · 927 Bytes
/
tac_typed.c
File metadata and controls
36 lines (33 loc) · 927 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
#include <stdio.h>
#include "slice.h"
NEW_SLICE_TYPE_HEADER(char, char)
NEW_SLICE_TYPE(char, char)
NEW_SLICE_TYPE_HEADER(char_slice, char_slice)
NEW_SLICE_TYPE(char_slice, char_slice)
int main() {
char_slice_slice bufarr = char_slice_new_slice(0, 5);
bufarr = char_slice_lappend_slice(bufarr, char_new_slice(0, 5));
int c;
while ((c = getchar()) != EOF) {
char_slice *buf_ptr;
switch (c) {
case '\n':
bufarr = char_slice_lappend_slice(bufarr, char_new_slice(0, 5));
break;
default:
buf_ptr = char_slice_slice_get_ptr(bufarr);
*buf_ptr = char_append_slice(*buf_ptr, c);
}
}
for (ssize_t i=0; i<bufarr.len; i++) {
char_print_slice(
slice_extract_char_slice(char_slice_sub_slice(bufarr, i, 1)),
print_char
);
}
for (ssize_t i=0; i<bufarr.len; i++) {
char_free_slice(slice_extract_char_slice(char_slice_sub_slice(bufarr, i, 1)));
}
char_slice_free_slice(bufarr);
return(0);
}