suppose the input file is...
5(number of cells)
1 2 -1 4
0 2 3 4
1 0 3 -1
2 -1 3 1
2 0 1 -1
how will i Write a function to read data from an input file to create a dynamic array of pointers to cells, create the required number of cells one by one, store their addresses at the corresponding index in the array. Then fill the data (given in the input file) in each cell.

It would be helpful to know what those numbers mean.

these are actually doors os a maze..
The four numbers indicate the cell numbers of the cells being led to through the respective door. -1 indicates absence of a door. For example, line number 2 is about cell number 0 and says that door 1 leads to cell 1, door 2 to cell 2, door 3 is absent, and door 4 leads to cell number 4.

If the first number is a cell number why are there duplicates ?

>>and says that door 1 leads to cell 1
There is no 1 on line 2. 0 2 3 4

its just an input format.......

So are you saying you just made up those numbers? You need to post some actual rows out of a real file.

The way I understand it, the first number is a cell number, second through fourth numbers are door numbers (three doors) and the value of the numbers indicate the cell number that the doors open to. If that is true then a cell is a square with only three doors, or only two doors when one of the door numbers is -1.

one more thing
whats the diffrence between
fin.get
and fin.getline??

getline() read an entire text line into the buffer. get() just read unformatted data, such as binary or text data.

There are two versions of getline() -- one for character arrays and the other for std::string.

std::string line;
char ln[255];
// character arrays
cin.getline( ln, sizeof(ln) );
//
// std::string
getline( cin, line );

thanks :)

#include<iostream>
#include<fstream>
using namespace std;

struct cell
{
	int *a[0];
	int *b[1];
	int *c[2];
	int *d[3];
	bool visited;
	int *back;
};
int main()
{
	int array[80];
	ifstream fin;
	ofstream fout;
	fin.open("input.txt");
	fout.open("output.txt");
	int num;
	while(!fin.eof())
	{
		fin>>num;
		for(int i=0; i<num; i++)
			fin.getline(array,80);
	}
	cout<<array;
	return 0;
}

i have tried this...
but *a[0]; is an error...
i cant understand this whole problem :(

am trying to read in the number of cells
and then read in line by line
and then i have to create dynamic array...
using function.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.