blob: 5313cb6507e3cf9f0a7b2785ee7d273d2a70fa6d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#define i_val_str
#include <stc/cvec.h>
#include <errno.h>
cvec_str read_file(const char* name)
{
cvec_str vec = cvec_str_init();
c_autovar (FILE* f = fopen(name, "r"), fclose(f))
c_autovar (cstr line = cstr_init(), cstr_drop(&line))
while (cstr_getline(&line, f))
cvec_str_emplace_back(&vec, line.str);
return vec;
}
int main()
{
int n = 0;
c_autovar (cvec_str vec = read_file(__FILE__), cvec_str_drop(&vec))
c_foreach (i, cvec_str, vec)
printf("%5d: %s\n", ++n, i.ref->str);
if (errno)
printf("error: read_file(" __FILE__ "). errno: %d\n", errno);
}
|