Im trying to write a program to read a file and determine a secondary index, which will be written to a file, and create lableID file which will hold a label of the data
Idea is kind of clear in my mind so I started simple, just to prove my point,
but as with every file including program, I get weird readings
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
|
#include <iostream>
#include <list>
#include <string>
#include <fstream>
using namespace std;
int main()
{
list<int> a;
char secIndex[9][9] ;
ifstream infile;
ofstream outfile,outfile1;
char c;
int delCount = 0;
int i =0;
int j =0;
infile.open("data.txt",ios::beg);
cout<<"input file was opened"<<endl;
outfile.open("SecondaryIndex.txt", ios::cur);
cout<<"output file 1 was opened"<<endl;
outfile1.open("LabelId.txt", ios::cur);
cout<<"output file 2 was opened"<<endl;
while(!infile.eof())
{
infile.seekg(1,ios::cur);
infile>>c;
if(c == '|')
{
cout << " found | "<<endl;
delCount++;
}
if (delCount % 3 == 0)
{
while ( c != '|')
{
outfile<<c;
infile>>c;
secIndex[i][j] = c;
outfile<<c;
j++;
cout<<secIndex[i][j];
}
i++;
}
}
}
|
I added random values for the data.txt file to see the results:
track1|song1|artist1|album1|
track2|song2|artist2|album2|
track3|song3|artist3|album3|
the first letter of each new word was missing and the remining letters were printed twice, althu I restricted the program to write the letters after the 3rd "|" only, all of them showed up.
General question:
Am I doing the right thing to get specific data from the files ?