-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_fstream.c
More file actions
55 lines (46 loc) · 1022 Bytes
/
test_fstream.c
File metadata and controls
55 lines (46 loc) · 1022 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
45
46
47
48
49
50
51
52
53
54
55
// #define OPENCSTL_TRACER
// #include "opencstl/opencstl.h"
//
// int main() {
// FILE *fp = file.open("../test.txt", "r");
// char *buf = file.read(fp);
//
// puts(buf);
// char *buf2 = string.reverse(buf);
// free(buf);
//
// puts(buf2);
//
// FILE *fp2 = file.write(fp, buf2);
// file.close(fp2);
//
// free(buf2);
// return 0;
// }
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "opencstl.h"
static int str_cmp(const void *a, const void *b)
{
const char * const *pa = a;
const char * const *pb = b;
return strcmp(*pa, *pb);
}
int main(void)
{
DEQUE(char *) array = new_deque(char *);
if (!array) {
abort();
}
push_front(array, "World");
push_front(array, "Hello");
push_front(array, "!");
// WORKAROUND: Use qsort directly on the underlying contiguous storage.
qsort(array, size(array), sizeof(char *), str_cmp);
for (int i = 0; i < size(array); i++) {
printf("%s\n", array[i]);
}
destroy(array);
return 0;
}