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 7784243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:03:50+00:00 2026-06-01T20:03:50+00:00

I have a problem with some strings created by a sequence alignment program (this

  • 0

I have a problem with some strings created by a sequence alignment program (this is a bioinformatics project). I am attempting to add additional functionality to an existing C program that parses alignment files but I’ve run into some issues with the parsing of a “mis match” string that the program creates. To add some context, here is an example of the alignment string:

example = “28G11AC10T32”;

Here is how to interpret the string: the first 28 bases match the sequence, then there is a “G” mismatch (29th base total), the next 11 bases match (40th base total), an “A” mismatch (41st base total), “C” mismatch (42nd base total), and so on…

I need to find out the base position where there are mismatches (ie, the string has a character instead of digits) and store that into an int array so that I can look this up in a later subroutine.

So here is where my issue comes into play. I have written a subroutine that I “thought” could parse this out, but I get a very strange artifact from the output. NOTE: please forgive my terrible and cluttered code! I am not a C programmer by any means and my training is not in computer science!

int errorPosition(char *mis_match, int *positions){
    int i = 0; //iterator for loop
    int pi = 0; //position array iterator
    int in = 0; //makeshift boolean to tell if values are inside the pre array
    int con = 0; //temporary holder for values converted from the pre array
    char pre[5]; //this array will hold the digit values that will be converted to ints
    pre[0] = '\0';
    for (i = 0; i < strlen(mis_match); i++){
        if(isalpha(mis_match[i]) && in == 1){
            con += atoi(pre);   // this is the part where I get an artifact (see below)
            positions[pi] = con;
            con++;
            pi++;
            in = 0;
            memset(&pre[0], 0, sizeof(pre));
            pri = 0;
        }else if(isalpha(mis_match[i]) && in == 0){
            positions[pi] = con;
            con++;
            pi++;
        }else if(isdigit(mis_match[i])){
            pre[pri] = mis_match[i];
            pri++;
            in = 1;
        }
    }
    if(pri > 0){
        con += atoi(pre);
        positions[pi] = con;
        pi++;
    }

}

So, my issue is that when I reach the segment that I have commented above (“this is where I get the error”), my “pre” string contains the digits times 10. For example, using the example string I listed above, the first time that the loop would reach that area I would expect that pre would contain “28”, but instead it contains “280”! When I use atoi to convert the string, it is therefore ten times higher than I expect.
Is there something that I am missing or some char array convention in C that I am ignorant of here? Thank you in advance for your replies.

  • 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-01T20:03:51+00:00Added an answer on June 1, 2026 at 8:03 pm

    This may not be the only issue, but you are not zero-terminating the string that you pass to atoi. The '0' character in the third position of 280 may be garbage, because you never wrote to that position of the array.

    To address this issue, you should add this line before the call of atoi:

    pre[pri] = '\0';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some problem to order an array by a field of this, here
i have a problem using some php functions on a string i get from
I have some problem with my code public IQueryable<PageItems> GetPageById(Guid Id) { var xml
I have some problem with Jquery Autocomplete plugin ( http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ ) I got it
I have some problem with my .htaccess file. Here I am adding my problem.
I have some problem whith such mysql_query INSERT INTO table VALUES ('', CURDATE()-1) why
I have some problem's with a simple application in JSF 2.0. I try to
I have some problem with my cfml website. I have used the below code
I have some problem when unmarshaling a .xml at a web service using JAXB.
Referring on this question , I have a similar -but not the same- problem..

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.