Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define size 25
main()
{
time_t start, Totalstart;
time_t finish, Totalfinish;
int matrix[size][size];
int patterntxt[size][size];
int parent[size][size];
int i,j;
int m,n;
int Xcoordinate;
int Ycoordinate;
int pattern=0;
int num=1;
int a;
FILE *MatrixA;
FILE *Patterns;
MatrixA = fopen("MatrixA.txt","w");
/*It's a rand() generated. Not going to show here.*/
fclose(MatrixA);
/*Scanning the patterns*/
ParentMatrix = fopen("MatrixA.txt","r");
Patterns = fopen("Patterns.txt","r");
/*Pattern starts*/
do
{
printf("Pattern can be found at ");
for(m=0; m!='='; m++)/*Get pattern from Patterns.txt*/
{
for(n=0; n!='\0'; n++)
{
for(i=0; i<size; i++)/*Get from MatrixA.txt*/
{
for(j=0; j<size; j++)
{
fscanf(ParentMatrix, "%d ", &parent[i][j]);
fscanf(Patterns, "%d ", &patterntxt[m][n]);
time(&start);
if (parent[i][j]==patterntxt[m][n] && parent[i][j+1]==patterntxt[m][n+1] && parent[i][j+2]==patterntxt[m][n+2] && parent[i+1][j]==patterntxt[m+1][n] && parent[i+1][j+1]==patterntxt[m+1][n+1] && parent[i+1][j+2]==patterntxt[m+1][n+2] && parent[i+2][j]==patterntxt[m+2][n] && parent[i+2][j+1]==patterntxt[m+2][n+1] && parent[i+2][j+2]==patterntxt[m+2][n+2])
{
/*printf something*/
}
else
{
pattern=0;
}
time(&finish);
}
}
printf("\nNumber of patterns found: %d\n", pattern);
printf("Time Taken: %.6f seconds\n", difftime(finish,start));
}
}
}while(patterntxt[m][n]!='=');
/*end of Pattern*/
printf("Search Done!\n");
fclose(MatrixA);
fclose(Patterns);
}
FileA...
1 1
1 1
*****
0 0
0 0
*****
2 2
2 2
Please help!