I'm writing a program which organizes a buses network.
these are the structs I use:
Code:
typedef struct lns{
int num;
struct lns *nextline;
}lns;
typedef struct stns{
int code;
struct stns *nextstn;
}stns;
typedef struct {
int num;
stns *stations;
}LINE;
typedef struct {
int SNcode;
int CTcode;
char city[30];
char adress[30];
lns *lines;
}STATION;
I have some functions that fill some data in structures.
Now, I got a function which ask for a station code & determine which lines pass this station.
Code:
FindLines (LINE *L)
{
int i=0, orgn, dest;
puts ("\nEnter origin station code first and destination station code second");
flushall();
scanf ("%d %d", &orgn, &dest);
while (L[i].stations->code && i<STN)
{
if (orgn==L[i].stations->code)
{
L[i].stations=L[i].stations->nextstn;
while (L[i].stations->code)
{
if (dest==L[i].stations->code)
{
printf ("line %d pass origin code %d station & destination code %d station", L->num, orgn, dest);
break;
}
else
puts ("No match found");
}
}
L[i].stations=L[i].stations->nextstn;
i++;
}
}
When I run it I get infenite output of "No match found", though my input has positive data.
Debugger shows I got stuck in last iteration of the top while loop, I think, with a memory allocation error.
Help will be highly epriciated!
Ronen