You are here:

C++/requesting for help in the following ..

Question
iam a bioinformatics student have knowledge in biology and little in programming..
we have 20 aminoacids like(a,b,c,d....), such that the combinations of occuring pairs is 20*20=400 chances of pairs
like(ab,ac,ad,bc,bd,ba,...). so i  need to calculate bigrams which are repetitively occuring(example:ab occurs 10 times,bc occurs 20 times) in given length(for example 300 element s of aminoacids like(abcddcbbccaaa....) of file?
so, please help me in the above .as i capable to write upto get the bigrams but i have a problem that how to count these   repeated bigrams by using file handling.
upto know to get the bigrams my code is as follows...

#include<stdio.h>
#include<string.h>
main()
{
char s[6],t[6];
int i,j,rep,count=0;
printf("enter the string");
scanf("%s", s);
printf("enter the 2nd string");
scanf("%s", t);
for(i=0;i<=4;i++)
{
for(j=0;j<=4;j++)
{
printf("%c,%c
", s[i],t[j]);

}

}
}

This exercise sounds like you want to find a substring in a larger string, and count them.  C provides a nice function for this: strstr.

Use strstr to find the substring.  If it returns NULL, you've reached the end of the string.  If not, it is the point of the match.  To resume searching to the end, take the return pointer and add the length of the match string:

char *string; // large string to search
char *part; // part to count in string
char *position;
int count;

count = 0; // Number of parts in string
position = string;
while( position )
{
position = strstr( position, part );
if( position != NULL )
{
++count;
position += strlen( part );  // resume after match
}
}

C++

Volunteer

Bill A

Expertise

I can answer questions about C++, programming algorithms, Windows programming in MFC (which is C++). I cannot answer questions about STL (templates) and I have no experience with Linux. I do enjoy reviewing code and critiquing it or finding problems in it. I will also gladly show better algorithms or methods if you want to take advantage of that.

Experience

I've developed a commercial embedded C compiler/assembler and IDE with debugger toolset, of which the IDE and debugger are written in C++. I work in the industry writing high tech embedded programs and Windows programs to communicate with the embedded devices.

Publications
Book: Embedded Systems Design using the Rabbit 3000 Microprocessor Authored Chapter 10 in its entirety.

Education/Credentials
BS Computer Engineering