| | |
function to read in data and create dynamic array of pointers
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2008
Posts: 10
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Nov 2008
Posts: 10
Reputation:
Solved Threads: 0
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.
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.
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.
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
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.
There are two versions of getline() -- one for character arrays and the other for std::string.
C++ Syntax (Toggle Plain Text)
std::string line; char ln[255]; // character arrays cin.getline( ln, sizeof(ln) ); // // std::string getline( cin, line );
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Nov 2008
Posts: 10
Reputation:
Solved Threads: 0
thanks 
i have tried this...
but *a[0]; is an error...
i cant understand this whole problem

C++ Syntax (Toggle Plain Text)
#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; }
but *a[0]; is an error...
i cant understand this whole problem
Last edited by Ancient Dragon; Apr 13th, 2009 at 8:55 pm. Reason: add code tags
![]() |
Similar Threads
- read line of text from file into array (C++)
- Differences Between Java and C/C++ (C++)
- fstream Tutorial (C++)
Other Threads in the C++ Forum
- Previous Thread: initializing an array to null
- Next Thread: Homework help with strings
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






