• C

# FInd the repeating words in sequence

I enter the sequence. for eg: ACTGCTACTG .

I need to find out the number of occurence of G and c in this string.

TIA
###### Who is Participating?

Commented:
kousis,
Your example sequence looks like a gene sequence to me.
In that case, it's probably going to very long but would only consists of 4 different letters.

So, i think the system approach proposed by dclaydon is better because the recursive approach will be very resource intensive.
0

Commented:
Two methods

1) The systematic approach - start from one end and check each character one at a time for each character and keep counts of each letter

2) Recursive
utilise the function char* strstr(str1, str2) from stdio.h

returns a pointer to the first occurance of str2 (excluding the null terminator) within str1
0

Commented:
Something like:

int NumG=0;
int NumC=0;
char *p;
char Target[256];

p=Target;
while (p<Target+strlen(Target))
{
if (*p=='G') NumG++;
if (*p=='c') Numc++;
p++;
)
0

Commented:
Is it always going to be full of characters?
Can there be numbers?
Will you ever do groups of words?
0

Commented:
int CountLetter(char* strSource, char cMatch)
{
int nCounter=0;
for (;strSource != '\0';strSource++)
if (*strSource == cMatch)
nCounter++;
}
0

Author Commented:
yes. it's DNA sequence
0

Commented:
Actually, i think the others contributed.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.