libstrvec-c

C string vector library
git clone https://git.sinitax.com/sinitax/libstrvec-c
Log | Files | Refs | LICENSE | sfeed.txt

test.c (595B)


      1#include "strvec.h"
      2#include "allocator.h"
      3
      4#include <err.h>
      5#include <string.h>
      6#include <stdio.h>
      7
      8#define LIBSTRVEC_ERR(rc) errx(1, "libstrvec: %s", strerror(-rc))
      9
     10int
     11main(int argc, const char **argv)
     12{
     13	struct strvec *strvec;
     14	const char **arg;
     15
     16	strvec = strvec_alloc(0, &stdlib_strict_heap_allocator, NULL);
     17
     18	if (!argc) return 1;
     19	for (arg = &argv[1]; *arg; arg++) {
     20		strvec_push(strvec, *arg);
     21	}
     22
     23	strvec_push(strvec, "--");
     24	strvec_push(strvec, "end");
     25	strvec_push(strvec, NULL);
     26
     27	for (arg = strvec_stra(strvec); *arg; arg++) {
     28		printf("%s\n", *arg);
     29	}
     30
     31	strvec_free(strvec);
     32}