The aim of the program which i am writing is to convert strings of DNA. The DNA is in a text file and represented by the letters A, T, C, and G. Reading in the file and outputting the converted DNA is easy. However i want to save the converted data in another array and then to a text file. Here is my code
#include <iostream>
#include <fstream>
#include "dna.h"
using namespace std;
int main()
{
fstream ins;
char name[128];
char savefile[128];
cout << "Enter file name to read: " << endl;
cin >> name;
ins.open(name, ios::in);
if (ins.good())
{
reverse(ins);
}
else
{
cout << "error" << endl;
}
ins.close();
cout << "Enter file to save to: " << endl;
cin >> savefile;
ins.open(savefile, ios::in);
if (ins.good())
{
write(ins);
}
else
{
cout << "error" << endl;
}
ins.close();
return 0;
}
#include <iostream>
#include <fstream>
#include "dna.h"
using namespace std;
ecoli sequence;
ecoli save;
int reverse(fstream& ins)
{
int i = 0;
while ((ins.good()) && (i < MAX))
{
ins.ignore(0,'\n');
ins >> sequence.dna[i];
if (ins.good())
{
i++;
}
}
for (int i = MAX - 1; i >= 0 ; i--)
{
if (sequence.dna[i] == 'A')
{
cout << 'T';
save.dna[i] = "T"; //i though this mwould work but it dosnt.
}
else if (sequence.dna[i] == 'T')
{
cout << 'A' ;
save.dna[i] = "A";
}
else if (sequence.dna[i] == 'C')
{
cout << 'G';
save.dna[i] = "G";
}
else if (sequence.dna[i] == 'G')
{
cout << 'C';
save.dna[i] = "C";
}
}
cout << endl;
return 0;
}
int write(fstream& ins)
{
}
#include <fstream>
using namespace std;
const int MAX = 3000;
struct ecoli
{
char dna[MAX];
};
int reverse(fstream&);
int write(fstream&);
how can i insert the output into a new array so i can save it to another file?