I have a string like ATGCCA... . This string will be transformed into an array of char as [ATG CCA ...]. I already know that ATG=1 and CCA=2, and I have defined these as double. How can I save the transformed matrix as a double? Here is my program now, but it doesn't work:
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
using namespace std;
int main() {
double ATG=1, CCA=2;
fstream fp("sequence.txt",ios::in);
if(!fp)
{
cerr<<"File can not open!"<<endl;
exit(1);
}
char content,k,l,m;
char a[4]="";
double n;
while(fp>>k>>l>>m){
fp.read(a, sizeof(a) - 1);
n=atof(a);
cout<<a<<" "<<n<<endl;
}
}
I expect to see this as output:
ATG 1
CCA 2
But what I see is:
ATG 0
CCA 0
Thank you for your help!