I encoded in C to solve the problem on the ROSALIND website. The code is very simple, and since it is so simple, it is very difficult to fix this error (I think) Here is my code:
#include <stdio.h>
int main(){
char nt;
int nA, nC, nG, nT;
for(int i = 0, nA = nC = nG = nT = 0; i < 1000; i++){
nt = getchar();
if(nt == 'A'){
nA++;
}else if(nt == 'C'){
nC++;
}else if(nt == 'G'){
nG++;
}else if(nt == 'T'){
nT++;
}else{
break;
}
}
printf(" %d %d %d %d", nA, nC, nG, nT);
}
And when I check this code:
AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC
He must give:
20 12 17 21
But my computer gives:
4200624 12 17 21
I found printf () functions to find the location of the error. I saw this at that moment, right before I exit the cycle nA = 20, but the moment immediately after it was nA = 4200624. What can I do?
source
share