sorry for that. The code is a little messy, but i've attached it below. Also, i've pasted part of the data file that goes along with it. The actually files are much larger, but this is how they would be set up. I've ran it on these smaller "sample files" and got the same results. Also, I'm compiling it with borland's command line compiler.
Code:
void main()
{
struct userStruct
{
unsigned int length;
unsigned long userID;
unsigned int* movieID;
unsigned short* rating;
};
unsigned long nVal = 480189;
userStruct* user;
user = new userStruct[nVal];
ifstream inFile;
ifstream inLen;
inFile.open("sample.dat");
inLen.open("len.dat");
unsigned int tempLength;
string line, l1, l2;
unsigned long tem;
unsigned int tem1;
unsigned short tem2;
unsigned long counter = -1;
while (!inFile.eof())
{
getline(inFile, line);
if (line.find(':') != string::npos)
{
counter++;
tem = atoi(line.c_str());
user[counter].userID = tem;
getline(inLen, line);
tem = atoi(line.c_str());
user[counter].movieID = new unsigned int[tem];
user[counter].rating = new unsigned short[tem];
user[counter].length = 0;
}
else
{
l1 = line.substr(0, line.find(' '));
l2 = line.substr(line.find(' ')+1, line.length()-line.find(' ')-1);
tem1 = atoi(l1.c_str());
tem2 = atoi(l2.c_str());
tempLength = user[counter].length;
user[counter].movieID[tempLength] = tem1;
user[counter].rating[tempLength] = tem2;
user[counter].length++;
}
}
inFile.close();
inLen.close();
for( int i = 0; i<3; i++)
{
cout<<user[i].length<<' '<<user[i].userID<<endl;
for (int j = 0; j< 4; j++)
cout<<' '<<user[i].movieID[j]<<' '<<user[i].rating[j]<<endl;
}
}
This is the sample file's contents:
Code:
6:
30 3
157 3
173 4
175 5
191 2
197 3
241 3
295 4
7:
8 5
28 4
30 5
83 5
175 5
185 4
191 4
257 5
273 4
283 5
8:
1144 4
1202 5
1428 4
1518 4
1719 1
1799 5
1843 3
and this is the file that contains the lengths to make each array (it's the closest thing I could think of to make a 'jagged' array)