problem with structure

F

friend.05

I have follwoing structure definition.


struct _graph_vertex {

char *label;
int exectime;
};

struct _graph_edge {

int produced, consumed, delay;
};

struct _graph {

graph_vertex vertices[MAX_VTX];
graph_edge_pointer adjmtx[MAX_VTX][MAX_VTX];
};



Now while implenting, when I refer to above structure it is giving
error of core dump.


graph_pointer graph_construct(int *src, int *snk, int cnt)
{
graph_type g;
graph_pointer gptr;
gptr = &g;
int i,m1,m2;
/* for(i=0;i<MAX_VTX;i++)
{
printf("Enter execution time for Vertex %d\n",i);
scanf("%d",&g.vertices.exectime);
printf("Enter label for Vertex %d\n",i);
scanf("%s",&g.vertices.label);
}
*/

for(i=0;i<cnt;i++)
{
printf("Enter Produced for Edge %d\n",i);
scanf("%d", &g.adjmtx[2]->produced);

(It gives core dump error if I use i(variable) inside adjmtx[][], but
when I use constnt adjmtx[1][1] it does not give error.)

}
}
 
B

BWIGLEY

friend.05 said:
I have follwoing structure definition.


struct _graph_vertex {

char *label;
int exectime;
};

struct _graph_edge {

int produced, consumed, delay;
};

struct _graph {

graph_vertex vertices[MAX_VTX];
graph_edge_pointer adjmtx[MAX_VTX][MAX_VTX];
};



Now while implenting, when I refer to above structure it is giving
error of core dump.


graph_pointer graph_construct(int *src, int *snk, int cnt)
{
graph_type g;
graph_pointer gptr;
gptr = &g;
int i,m1,m2;
/* for(i=0;i<MAX_VTX;i++)
{
printf("Enter execution time for Vertex %d\n",i);
scanf("%d",&g.vertices.exectime);
printf("Enter label for Vertex %d\n",i);
scanf("%s",&g.vertices.label);
}
*/

for(i=0;i<cnt;i++)
{
printf("Enter Produced for Edge %d\n",i);
scanf("%d", &g.adjmtx[2]->produced);

(It gives core dump error if I use i(variable) inside adjmtx[][], but
when I use constnt adjmtx[1][1] it does not give error.)

}
}


Can't tell if this helps, but is cnt given a value anywhere, if so is
it in range?
 
F

friend.05

yes I hace give value of cnt

friend.05 said:
I have follwoing structure definition.


struct _graph_vertex {

char *label;
int exectime;
};

struct _graph_edge {

int produced, consumed, delay;
};

struct _graph {

graph_vertex vertices[MAX_VTX];
graph_edge_pointer adjmtx[MAX_VTX][MAX_VTX];
};



Now while implenting, when I refer to above structure it is giving
error of core dump.


graph_pointer graph_construct(int *src, int *snk, int cnt)
{
graph_type g;
graph_pointer gptr;
gptr = &g;
int i,m1,m2;
/* for(i=0;i<MAX_VTX;i++)
{
printf("Enter execution time for Vertex %d\n",i);
scanf("%d",&g.vertices.exectime);
printf("Enter label for Vertex %d\n",i);
scanf("%s",&g.vertices.label);
}
*/

for(i=0;i<cnt;i++)
{
printf("Enter Produced for Edge %d\n",i);
scanf("%d", &g.adjmtx[2]->produced);

(It gives core dump error if I use i(variable) inside adjmtx[][], but
when I use constnt adjmtx[1][1] it does not give error.)

}
}


Can't tell if this helps, but is cnt given a value anywhere, if so is
it in range?
 
K

Keith Thompson

friend.05 said:
I have follwoing structure definition.

struct _graph_vertex {

char *label;
int exectime;
};

Don't use identifiers starting with underscores. Many of them are
reserved to the implementation. It's easier to avoid them altogether
than to remember the details.
struct _graph_edge {

int produced, consumed, delay;
};

struct _graph {

graph_vertex vertices[MAX_VTX];
graph_edge_pointer adjmtx[MAX_VTX][MAX_VTX];
};

You haven't shown us types "graph_vertex" and "graph_edge_pointer".
Now while implenting, when I refer to above structure it is giving
error of core dump.


graph_pointer graph_construct(int *src, int *snk, int cnt)

Or "graph_pointer".
{
graph_type g;

Or "graph_type".

[snip]

Show us real code, and we might be able to help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,225
Latest member
Top Crypto Podcasts

Latest Threads

Top