finding letters in a string..

Discussion in 'C' started by tomas7470, May 9, 2012.

  1. tomas7470

    tomas7470 New Member

    Joined:
    May 5, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    This function gets a sequence in string and return 1 if all the letters in the string are
    comprised of capitalized ACGT. At the last place of the string there is ‘\0’. In case there is
    a char which is not ACGT in the string, the function returns 0.

    Code:
    int isLegitSequence(char sequence[])
    {
        int i = 0, j;
    
        while(sequence[i] != '\0')
    	{
            i++;
        }
    
        for (j = (i-1) ; j >= 0 ; j--)
    	{
            if((sequence[j] != 'A') || (sequence[j] != 'G') || (sequence[j] != 'C') || (sequence[j] != 'T'))
    		{
                return 0;
            }
        }
    	return 1;
    }
    
     
  2. hobbyist

    hobbyist New Member

    Joined:
    Jan 7, 2012
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    0
    if you mean something like like "does AGCT exist in this string?" then couldn't you just use strstr?

    Code:
    int isLegitSequence(char *sequence, char *pattern) {
    
       return (strstr(sequence, pattern) != NULL ? 1 : 0);
    }
     
  3. tomas7470

    tomas7470 New Member

    Joined:
    May 5, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    no the string can only be with those capitallized chars 'A', 'C', 'G' or 'T'....
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice