Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8723131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:33:26+00:00 2026-06-13T07:33:26+00:00

I am working on conversion of DNA sequence to Protein sequence. I had completed

  • 0

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

OUTPUT REQUIRED :

StopStop
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:33:28+00:00Added an answer on June 13, 2026 at 7:33 am

    strtok() has to be employed only on duplicate copies of strings as it overwrites "delimiters" with ‘\0’ to generate tokens when necessary.

    below code will chop the string:

    x = c1[k].dna_codon;
    pch = strtok(x, ",");
    

    e.g:

    String = "CTT, CTC, CTA, CTG, TTA, TTG"

    after first strtok() call a ‘\0’ overwrites ‘,’

    String = "CTT"\0" CTC, CTA, CTG, TTA, TTG" chopping the string. ‘\0’ added for readability.

    As strtok() keeps pointer to rest of the string, you’re safe for the first loop. During second loop string will only be:

    String = "CTT"

    PS: for performance, you can have array of strings instead of dna_codon[40] or a linked list if feasible. Chopping/locating delimiter for every comparison is a overhead.

    IEEE Std 1003.1-2008 strtok()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working on a program, and there's one line of my code that is giving
I was working on a infix to postfix program(using stacks) but after all those
I'm working on a Unit Conversion Module. I've found several good ideas here, as
My team is working on a conversion project to convert one product (but with
I'm working with ExpertPDF's Html-to-PDF conversion utility for this question (although I'm open to
Working with an undisclosed API, I found a function that can set the number
Working with H2 I get this error when I try to write a row
Working with JSF 2.0 (and Primefaces), is there a way to fire an ActionListener
I'm having a problem getting this type conversion working correctly. My guess is the
I'm currently working on a conversion script to transfer a bunch of old data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.