Mostafiz
Mostafiz

Reputation: 1687

datastructure/abtract data type with C which acts like vectors in C++

Hi I am using a C compiler(GCC) where I cannot use a vector like in C++. So how can I create similar kind of data structure/dynamic array with c which will work like a vector? It might be very easy but I don't have any idea how can I do it.

thanks

Upvotes: 0

Views: 78

Answers (1)

Jerry Coffin
Jerry Coffin

Reputation: 490428

Start with a struct holding a pointer to the correct type the currently used size, and the current allocation size. Allocate space with malloc. If you run out of space, use realloc to increase it.

Upvotes: 1

Related Questions