#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string>
usingnamespace std;
typedefstruct {
char* name;
int number;
} SomeStruct;
//function prototypes
char * getbuf(SomeStruct ***ptrs);
SomeStruct * GetNextSomeStruct(void);
int main()
{
// array of pointers to SomeStruct
SomeStruct **array_ptrs = NULL;
char * b, q, *r;
b=getbuf(&array_ptrs);
//I want to do something like this
//to fill the array_ptrs with data but I keep getting errors
//array_ptrs[2][1] = GetNextSomeStruct();
//I tried to test it like this but it crashes here too
array_ptrs[2][1].number = 8;
q = *b;
}
char * getbuf(SomeStruct ***ptrs)
{
char buff[8] ;
//int n = 5; //can also be determined by user at runtime
// allocate the memory for the array
int m;
*ptrs = (SomeStruct**)malloc( sizeof( SomeStruct* )* n );
for (m = 0; m < 1; m++)
{
(*ptrs)[m] = (SomeStruct*)malloc( sizeof( SomeStruct ) * n );
}
return (char *) buff;
}
// Return the next structure (to fill the
// abovementioned array with).
SomeSeq * GetNextSomeStruct()
{
//I don't really know what I should do here
//create some data and then return it to
//array_ptrs in main.
SomeStruct *p=NULL;
p = (SomeStruct*)malloc( sizeof( SomeStruct* ) );
return p ;
}
ah, templates are an attribute I'm pretty sure is not supported in C, so that won't work...
Try and find the source code for the vector template class, and reverse engineer it to create your own vector class. If you need any help with that just ask me, I've done stuff like it before as a test of my own skills.
I might note, the first line of your file looks to me like a c++ style header...