Member Avatar for simonsayz27

I don't know what in the world I'm doing wrong but I'm sick of staring at my screen and debugging over and over again. It's been a while since I've used C++ so I'm a bit rusty. I'm working on a database project that is supposed to implement a hash join algorithm. My problem is basically trying to read a text file which consist of integer numbers that are ordered by row column format (file 1 is 10 x 3 and file 2 is 10 x 4) and each number spaced apart. The output for file one turns out 99% fine besides for the first few numbers and file two outputs a bunch of random numbers no where close to my file. Part of my code is attached below so help me point out what I'm doing wrong. Thanks a ton!
Also, if there is a better way to make a hash-join, please let me know.

int main()
{
    int arrayR1[10][3] = {0};
    int arrayR2[10][4] = {0};

    ifstream fileR2;
    ifstream fileR1;

    fillArray(fileR1, fileR2, arrayR1, arrayR2);

    return 0;
}

void fillArray(ifstream &fileR1, ifstream &fileR2, int arrayR1[][3], int arrayR2[][4])
{
    fileR1.open("fileR1.txt");
    fileR2.open("fileR2.txt");

    for(int i = 0; i < 11; i++){
        for(int j = 0; j < 3; j++){
                fileR1 >> arrayR1[i][j];    
            }
        }
    }

    for(int k = 0; k < 11; k++){
        for(int l = 0; l < 4; l++){
            fileR2 >> arrayR2[k][l];
        }
    }

}

Data in fileR1:

5 23 42
7 19 32 
3 33 28 
18 23 42
28 14 17
2 32 7
36 27 14
9 34 42 
5 15 27 
8 23 5 
34 6 20

Output: (I deleted the cout statements for simplicity)
fileR1:

23942
71932
33328
182342
281417
2327
362714
93442
51527
8235
34620

File 2 is just a bunch of random numbers so I left it out for now. Thanks for the help in advance.

Regards,
Simon

for(int i = 0; i < 11; i++){

Why 11?

You can use the fscanf method.

int buf1[100];

fp1=fopen("data.in","r");                                             // Open the file containing data in the input mode
if(fp1==NULL)
{
 printf("%s","Could not open source data file");            // If the file cannot be opened the program exits
 exit(1);
}
else
{
 while(!feof(fp1))
  fscanf(fp1,"%d",&buf1[i++]);						// Read the data into the array buf1	
 i--;
}

PS. I am not sure if this is the best way to do what you want . Can somebody please comment on the above code ....

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.