eteran / c-vector

A dynamic array implementation in C similar to the one found in standard C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] example of vector of chars

Hillard28 opened this issue · comments

Do you happen to have an example of a c-vector of chars? Having a bit of trouble adapting the example and would be helpful to see that implementation!

I assumed chars are supported but is it just numerics?

It should support any type!

I haven't tested it, but just off the top of my head, I'd expect this to work:

// declare it as a vector of chars
cvector_vector_type(char) v = NULL;

// populate it
cvector_push_back(v, 'h');
cvector_push_back(v, 'i');
cvector_push_back(v, '!');
cvector_push_back(v, '\0');

// use it
printf("%s\n", v);

// free it
cvector_free(v);

Note that it won't automatically put the \0 terminator in there for you since this is just storage, so you'll have to manage that on your own if you intend to use this for c-string APIs (as shown above)

Closing because I believe this answers your question. But please re-open if you run into any issues.