hello guys, hope u're fine. i would like to ask your opinion on how to read the data from text file. The data doesn't have a fixed number in its rows. I give u the example :
2
9
1 4 3
7 4 5
3 5 4 1
4 4 3 2 0
2 3 1
4 8 4 2 1 Figure 1.0
6 8 7 5 3 1 0
4 7 6 4 0
2 7 5
4 8 6 5 4
3 7 4 3
As u can see above, the two earliest numbers (2 and 9) ->
type 1 : 2 => represents 1 4 3
7 4 5
Type 2 : 9 => represents from 3 5 4 1
4 4 3 2 0 etc..
From type 2 ,the leftmost value will determine how mane that the loop should read for the next number. For example 3 5 4 1
the leftmost -> 3 . And u can see this 3, is followed by another three numbers (5 4 1).
I have an idea to connect type 1 and type 2. My idea works like this:
from type 1 u can first row contain 1 4 3. In my program, what I want is, whenever my program reach to 1 for example, then it will return 4 3 2 0 (from type 2). And same goes to others.
My problems are :
1. how I can read this consecutives numbers
2. How I can connect the type 1 and type 2 data ?
I'm not expert in array but I prefer to use array. Below is my program code, but it doesn't works like what I want. i hope anyone can help me....
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include<iostream>
#include<fstream>
using namespace std;
int **m;
void readdata1();
void readdata2();
int noofvert,bil,*mh,*num;
void main()
{
readdata1();
}
void readdata1()
{
ifstream infile;
infile.open("Sorted final.txt");
if(infile.fail())
{
cout << " hahahha..Sorry u cannot open this file .." << endl;
}
infile >> bil;
infile >> noofvert;
m = new int*[bil];
for(int i=0;i<bil;i++)
m[i] = new int[3];
mh = new int[noofvert];
num = new int[noofvert];
for(int i=0;i<bil;i++)
{
infile >> m[i][0] >> m[i][1] >> m[i][2];
}
for(int j=0;j<noofvert;j++)
{
infile >> mh[j];
for(int k=0;k<mh[j];k++)
{
infile >> num[k];
}
}
readdata2();
}
void readdata2()
{
string parse;
for(int i=0;i<bil;i++)
{
for(int k=0;k<noofvert;k++)
{
if(m[i][0] == k)
cout << mh[k] << endl;
}
}
}
I hope anyone can help me to figure out, what is wrong in my code..thank you very very much for ur help...
thank you...
| |