You are here:

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


iam a bioinformatics student have knowledge in biology and little in programming..
sir, please help me in the following problem in c 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...

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);
", s[i],t[j]);

sir ,please help me as early as possible.
thank you for your help.

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 )
   position += strlen( part );  // resume after match


All Answers

Answers by Expert:

Ask Experts


Bill A


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.


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.

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

BS Computer Engineering

©2016 All rights reserved.