conversion of DNA to Protein - c structure issue

Posted by sam on Stack Overflow See other posts from Stack Overflow or by sam
Published on 2012-10-24T16:48:40Z Indexed on 2012/10/24 17:00 UTC
Read the original article Hit count: 330

Filed under:
|

I am working on conversion of DNA sequence to Protein sequence.
I had completed all program only one error I found there is of structure.
dna_codon is a structure and I am iterating over it.In first iteration it shows proper values of structure but from next iteration, it dont show the proper value stored in structure.

Its a small error so do not think that I havnt done anything and downvote. I am stucked here because I am new in c for structures.

CODE :

#include <stdio.h>  
#include<string.h>


void main()
{

int i, len;
char short_codons[20];
char short_slc[1000];
char sequence[1000];

struct codons
{
    char amino_acid[20], slc[20], dna_codon[40];
};

struct codons c1 [20]= {
                        {"Isoleucine", "I", "ATT, ATC, ATA"},
                        {"Leucine", "L", "CTT, CTC, CTA, CTG, TTA, TTG"},
                        {"Valine", "V", "GTT, GTC, GTA, GTG"},
                        {"Phenylalanine", "F", "TTT, TTC"},
                        {"Methionine", "M", "ATG"},
                        {"Cysteine", "C", "TGT, TGC"},
                        {"Alanine", "A", "GCT, GCC, GCA, GCG"},
                        {"Proline", "P", "CCT, CCC, CCA,CCG "},
                        {"Threonine", "T", "ACT, ACC, ACA, ACG"},
                        {"Serine", "S", "TCT, TCC, TCA, TCG, AGT, AGC"},
                        {"Tyrosine", "Y", "TAT, TAC"},
                         {"Tryptophan", "W", "TGG"},
                        {"Glutamine", "Q", "CAA, CAG"},
                        {"Aspargine","N" "AAT, AAC"},
                        {"Histidine", "H", "CAT, CAC"},
                        {"Glutamic acid", "E", "GAA, GAG"},
                        {"Aspartic acid", "D", "GAT, GAC"},
                        {"Lysine", "K", "AAA, AAG"},
                        {"Arginine", "R", "CGT, CGC, CGA, CGG, AGA, AGG"},
                        {"Stop codons", "Stop", "AA, TAG, TGA"}
                        };


int count = 0;

printf("Enter the sequence: ");
gets(sequence);

char *input_string = sequence;
char *tmp_str = input_string;

int k;
char *pch;

while (*input_string != '\0')
{
    char string_3l[4] = {'\0'};
    strncpy(string_3l, input_string, 3);
    printf("\n-----------%s & %s----------", string_3l, tmp_str );
    for(k=0;k<20;k++)
    {
        //printf("@REAL -  %s", c1[0].dna_codon);
        printf("@ %s", c1[k].dna_codon);
        int x;
        x = c1[k].dna_codon;
        pch = strtok(x, ",");
        while (pch != NULL)
        {
            printf("\n%d : %s with %s", k, string_3l, pch);
            count=strcmp(string_3l, pch);
            if(count==0)
            {
                strcat(short_slc, c1[k].slc);
                printf("\n==>%s", short_slc);
            }
        pch = strtok (NULL, " ,.-");
        }
    }
input_string = input_string+3;
}

printf("\nProtien sequence is : %s\n", short_slc);
}

INPUT :

TAGTAG

OUTPUT :
If you see output of

printf("\n-----------%s & %s----------", string_3l, tmp_str );   

in both iterations, we found that values defined in structure are reduced.

I want to know why structure reduces it or its my mistake? because I am stucked here

© Stack Overflow or respective owner

Related posts about c

    Related posts about structure