Reading tab-delimited file using fscanf( ) - File having information of a graph

Folks. I have a network data file that looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
24	76
1	1	2
2	1	3
3	2	1
4	2	6
5	3	1
6	3	4
7	3	12
8	4	3
9	4	5
.	.	.
.	.	.
.	.	.


The first row has two values - number of nodes (24) and number of links (76). Then it has all the link details (76 rows of data). I want to read this data. I have written out the following function:

First the structure definitions:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
typedef struct {
	int arcno;
	int tail;
	int head;
} arc_data;

typedef struct {
	int forwardStarPoint;
	int reverseStarPoint;
} node_data;

typedef struct {
	arc_data *arcs;
	node_data *nodes;
	int numNodes;
	int numArcs;
}  network_data;


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//Reading the network data
network_data readNetwork(char *filename) {
	int i, j;
	network_data network;

	/*Read network details - Number of arcs and node*/

	FILE *output = fopen(filename, "rb");
		if (output == NULL){
			cout<<"Error opening file "<<filename; 
		}
		fscanf(output, "%u\t%u", &network.numNodes, &network.numArcs);
		cout<<"\nNodes = "<< network.numNodes;
		cout<<"\nArcs = "<< network.numArcs;

	/* Read arc data */
	for(i = 1; i <= network.numArcs; i++) {
		fscanf(output, "%u\t%u\t%u", &network.arcs[i].arcno, &network.arcs[i].tail, &network.arcs[i].head); 
	}
	
	return network;
}

The code is able to read the first line of data (i.e. it displays the numNodes and numArcs as 24 and 76). But then I get a lot of errors like this one

`Access violation writing location 0xCCCCCCD8`.

The program then crashes.

Can anyone please help me out here?
Last edited on
show your code for network_data class.
Updated... The network_data is a structure and not a class.
The difference being...

¿where are `arcs' and `nodes' pointing to?
Topic archived. No new replies allowed.