-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
27 lines (19 loc) · 884 Bytes
/
test.c
File metadata and controls
27 lines (19 loc) · 884 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
#include <stdio.h> // for printf
#include <stdlib.h> // for free
// Only define this in **one** if you C source files if
// you are not compiling with catpath.c
#define CATPATH_IMPLEMENTATION
#include "catpath.h"
int main() {
// You must init the first path with NULL!
char* some_path = NULL; // You must init the first path with NULL!
// Create a new allocated pointer for `some_path` with contents of: `/starts/with/slash-and-end-with-slash` (removes the suffix '/')
catpath(&some_path, "/starts/with/slash-and-end-with-slash/");
// Append a path to `some_path`, will automatically free/alloc a new pointer and return it
catpath(&some_path, "/other/path");
printf("some_path: %s\n", some_path);
// some_path contents: /starts/with/slash-and-end-with-slash/other/path
// When you are done, make sure you `free()` the path.
free(some_path);
return 0;
}