N
nobrow
Okay ... Im out of practice. Is it not possible to have a 2D array
where each column is of a different type, say an int and a struct*? The
following seg faults for me and I cant figure out what I need to
change.
Thanks.
#include <malloc.h>
#include <string.h>
void*** a;
void f();
typedef struct
{
char* name;
int idx;
} A_Type;
int main()
{
f();
}
void f()
{
int i;
a = malloc(sizeof(void**) * 2);
a[0] = malloc(sizeof(int) * 10);
a[1] = malloc(sizeof(A_Type*) * 10);
A_Type* tmp;
for(i = 0; i < 10; i++)
{
tmp = malloc(sizeof(A_Type));
tmp->name = "My Name";
tmp->idx = i;
memcpy(a[0], &i, sizeof(int)); /* SEG FAULT HERE */
a[1] = tmp;
}
}
where each column is of a different type, say an int and a struct*? The
following seg faults for me and I cant figure out what I need to
change.
Thanks.
#include <malloc.h>
#include <string.h>
void*** a;
void f();
typedef struct
{
char* name;
int idx;
} A_Type;
int main()
{
f();
}
void f()
{
int i;
a = malloc(sizeof(void**) * 2);
a[0] = malloc(sizeof(int) * 10);
a[1] = malloc(sizeof(A_Type*) * 10);
A_Type* tmp;
for(i = 0; i < 10; i++)
{
tmp = malloc(sizeof(A_Type));
tmp->name = "My Name";
tmp->idx = i;
memcpy(a[0], &i, sizeof(int)); /* SEG FAULT HERE */
a[1] = tmp;
}
}