I'm having problems with a C++ program I'm writing.
Basically, I need to get a line from one file, loop through another file, and repeat until the end of the first file.
The problem is that it's not looping through the whole first file, just one line.
Here's the code:
Basically, I need to get a line from one file, loop through another file, and repeat until the end of the first file.
The problem is that it's not looping through the whole first file, just one line.
Here's the code:
Code: Select all
And here's what I think is the problem spot:
#include <fstream>
#include <iostream>
using namespace std;
int list() {
ofstream fout("primes.txt");
int i, j;
int numbers = 200;
for ( i = 2; i < numbers; i++ ){
for ( j = 2; j <= i/2; j++ ){
if ( ! ( i % j ) ) break;
}
if ( j > i / 2 ) fout << i << endl;
}
return 0;
fout.close();
}
int factor(){
ifstream ifcopy("primes.txt", std::ios::binary);
ofstream ofcopy("primes2.txt", std::ios::binary);
ofcopy << ifcopy.rdbuf();
ofcopy.close();
ifcopy.close();
ofstream fout("factors.txt");
ifstream fin2("primes2.txt");
ifstream fin("primes.txt");
long double prime1;
long double prime2;
long double composite;
fin2 >> prime1;
fin >> prime2;
while (!fin2.eof()){
while (!fin.eof()){
composite = prime1 * prime2;
fout << "INSERT INTO factor (composite, prime1, prime2) VALUES ( " << composite << ", " << prime1 << ", " << prime2 << ")" << endl;
fin >> prime2;
}
fin2 >> prime1;
}
fout.close();
fin.close();
fin2.close();
return 0;
}
int main(){
cout << "RSA Tables -- v -0.1 -- Written By Flapjack\n\n\n";
cout << "GENERATING PRIMES...\n";
list();
cout << "LIST OF PRIMES GENERATED.\n";
cout << "CREATING TABLE...\n";
factor();
cout << "TABLE CREATED.\n";
cout << "RSA TABLE CREATED.\n";
return 0;
}
Code: Select all
[/code]while (!fin2.eof()){
while (!fin.eof()){
composite = prime1 * prime2;
fout << "INSERT INTO factor (composite, prime1, prime2) VALUES ( " << composite << ", " << prime1 << ", " << prime2 << ")" << endl;
fin >> prime2;
}
fin2 >> prime1;
}
