If you are using linux you can approximate a C++ vector using a dynamic memory buffer stream (aka a memstream).
Here's an example of how you might go about that:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int *ints = NULL;
size_t len = 0;
FILE *mem;
if( (mem = open_memstream( (char **)&ints, &len)) == NULL ) {
return 1;
}
for(int i = 0; i < 10; ++i) {
int n = i * 2;
ssize_t written = fwrite(&n, sizeof n, 1, mem);
if(written != 1) {
}
}
fflush(mem);
size_t nints = len / sizeof(int);;
for(int i = 0; i < nints; ++i) {
printf("%d\n", ints[i]);
}
for(int i = 0; i < 10; ++i) {
int n = (100+i);
size_t written = fwrite(&n, sizeof n, 1, mem);
if(written != 1) {
}
}
fclose(mem);
nints = len/sizeof(int);
for(int i = 0; i < nints; ++i) {
printf("%d\n", ints[i]);
}
free(ints);
return 0;
}
Next step might be to write a struct like
struct MEMDATA {
char *data;
size_t data_size;
size_t mem_size;
FILE *fp;
};
and write some functions that take a
struct MEMDATA
to create a new MEMDATA, push data, get the data pointer, etc.