-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranscribe_DNA_to_RNA.cpp
63 lines (45 loc) · 1.1 KB
/
transcribe_DNA_to_RNA.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
transcribe DNA to RNA
replace T in t, with U in u
where t is a DNA string
and u is a RNA string
*/
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main(int argc, char const *argv[])
{
const char * filename = *(argv + 1);
ifstream inFile;
inFile.open(filename);
string dna_string;
getline(inFile, dna_string);
inFile.close();
//get length of dna_string
char dna_char = dna_string[0];
int i = 0;
while(dna_char){
dna_char = dna_string[i];
i++;
}
int dna_length = i;
char * rna_string = (char *)malloc(sizeof(char) * dna_length);
//swap T's and U's
i = 0;
for(i; i < dna_length; i++){
//get DNA char
char cur_dna_char = dna_string[i];
if(cur_dna_char != 'T'){
*(rna_string + i) = cur_dna_char;
} else {
*(rna_string + i) = 'U';
}
}
cout << dna_string << endl;
cout << rna_string << endl;
free(rna_string);
return 0;
}