#include typedef struct { int x[1000000], length; } String; String dna[10]; void translate(int type) { char original[1000000], filename[100]; FILE *fp; int i=0; printf("Enter the location of the string\n"); scanf("%s", filename); fp=fopen(filename, "r"); if (fp == NULL) {printf("Can't open file\n"); exit(1);} fscanf(fp, "%s", original); while ((original[i]) =='g' || (original[i]) =='a' || (original[i]) =='c' || (original[i]) =='t') { if((original[i])=='a') { dna[type].x[i]=1;} else if((original[i])=='c') { dna[type].x[i]=2;} else if((original[i])=='g') { dna[type].x[i]=3;} else {dna[type].x[i]=4;} i++; } dna[type].length=i; } int main() { int i, j, true, match=0; printf("for the full dna string:\n"); translate(0); printf("for the substring we are searching for:\n"); translate(1); for(i=0; i < dna[0].length-dna[1].length; i++) { j=i; true=0; while (j < i+dna[1].length) { if(dna[0].x[j] == dna[1].x[j-i]) {true++;} j++; } if(true == dna[1].length) {match++;} } printf("this substring has appeared %d times\n\n",match); }