Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# FInd the repeating words in sequence

Posted on 2002-06-27
Medium Priority
372 Views
I enter the sequence. for eg: ACTGCTACTG .

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

TIA
0
Question by:kousis
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 1

Expert Comment

ID: 7113219
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

LVL 22

Expert Comment

ID: 7114457
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

LVL 6

Expert Comment

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

LVL 1

Accepted Solution

harrlow earned 150 total points
ID: 7115624
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

LVL 10

Expert Comment

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

Author Comment

ID: 7116413
yes. it's DNA sequence
0

LVL 1

Expert Comment

ID: 7121768
Actually, i think the others contributed.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were smallâ€¦
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see soâ€¦
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
###### Suggested Courses
Course of the Month10 days, 6 hours left to enroll