Home > Archive > Unix Programming > September 2006 > Structure
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| friend_05 2006-09-29, 9:59 pm |
| I have following structure definition
struct graph_vertex {
char *label;
int exectime;
};
struct graph_edge {
int produced, consumed, delay;
};
struct graph {
graph_vertex vertices[3];
graph_edge * adjmtx[3][3];
};
graph_construct(int *a, int *b, int cnt)
{
graph g;
for(i=0;i<cnt;i++)
{
printf("Enter Produced for Edge %d\n",i);
scanf("%d", &g.adjmtx[a[i]][b[i]]->produced);
Above satement gives core dump error, but it does to give error when I
use g.admtx[1][2]->produced.
}
}
| |
| zhengda 2006-09-29, 9:59 pm |
| friend_05 wrote:
> I have following structure definition
>
> struct graph_vertex {
>
> char *label;
> int exectime;
> };
>
> struct graph_edge {
>
> int produced, consumed, delay;
> };
>
> struct graph {
>
> graph_vertex vertices[3];
> graph_edge * adjmtx[3][3];
> };
>
>
>
> graph_construct(int *a, int *b, int cnt)
> {
> graph g;
>
>
>
> for(i=0;i<cnt;i++)
> {
> printf("Enter Produced for Edge %d\n",i);
> scanf("%d", &g.adjmtx[a[i]][b[i]]->produced);
> Above satement gives core dump error, but it does to give error when I
> use g.admtx[1][2]->produced.
>
> }
> }
>
It seems that you didn't allocate the space for every entry of the array
adjmtx.
| |
| friend_05 2006-09-29, 9:59 pm |
| hi,
how to allocate space ?
zhengda wrote:
> friend_05 wrote:
> It seems that you didn't allocate the space for every entry of the array
> adjmtx.
| |
| Cong Wang 2006-09-30, 4:00 am |
|
friend_05 wrote:
> hi,
>
> how to allocate space ?
>
Use the C standard lib function malloc(). See the faq of comp.lang.c .
;-p
|
|
|
|
|