/*??????????????????????????????????????????????????????????????-*/
/* This program initializes a long character string and a short */
/* character string. It then prints the locations of the short */
/* string in the long string. It also prints the number of */
/* occurrences of the short string in the long string. */
#include <stdio.h>
#include <string.h>
#define long_leng 26
#define short_leng 3
int main(void)
{
/* Declare and initialize variables. */
int count=0;
printf("Enter sequence for long string DNA: ");
char long_str[long_leng];
scanf("%s", long_str);
printf("Enter sequence for short string DNA: ");
char short_str[short_leng];
scanf("%s", short_str);
char *ptr1=long_str, *ptr2=short_str;
/* Count the number of occurrences of short_str in long_str. */
/* While the function strstr does not return NULL, increment */
/* count and move ptr1 to next character of the long string. */
while ((ptr1=strstr(ptr1,ptr2)) != NULL)
{
printf("location %i \n",ptr1-long_str+1);
count++;
ptr1++;
}
/* Print number of occurrences. */
printf("number of occurrences: %i \n",count);
printf("\nLong String of DNA: ");
printf(long_str);
printf("\nShort String of DNA: ");
printf(short_str);
/* Exit program. */
return 0;
}
No comments:
Post a Comment