1 /*A list of helper functions*/
6 /*Prints text and pattern*/
7 void print_pattern( char **text
, char **pattern
, int m
, int n
)
11 /*Prints the pattern*/
12 for( j
= 0; j
< m
; j
++ ) {
13 for( i
= 0; i
< m
; i
++ )
14 printf("%i",pattern
[j
][i
]);
20 for( j
= 0; j
< n
; j
++ ) {
21 for( i
= 0; i
< n
; i
++ )
22 printf("%i",text
[j
][i
]);
28 /*Returns the square of a number*/
29 int power(int number
, int power
)
31 int i
, returned_number
= number
;
33 for( i
= 1; i
< power
; i
++ )
34 returned_number
= returned_number
* number
;
36 return returned_number
;
39 /*Loads text and pattern into tables*/
40 void load_files( char **text
, char **pattern
, int m
, int n
)
42 FILE *text_fp
, *pattern_fp
;
49 pattern_fp
= fopen("data/pattern", "r");
51 for(j
= 0; j
< m
; j
++)
52 for(i
= 0; i
< m
; i
++) {
53 c
= fgetc( pattern_fp
);
54 /* If we encounter '\n' pull the next character*/
58 pattern
[j
][i
] = fgetc( pattern_fp
);
64 text_fp
= fopen("data/text", "r");
66 for( j
= 0; j
< n
; j
++ )
67 for( i
= 0; i
< n
; i
++ ) {
69 /* If we encounter '\n' pull the next character*/
73 text
[j
][i
] = fgetc( text_fp
);
79 /*Loads text and pattern into tables*/
80 void create_files(int pattern_size
, int text_size
, int alphabet
)
82 FILE *text_fp
, *pattern_fp
;
86 /* initialize random seed: */
87 srand( time( NULL
) );
90 pattern_fp
= fopen("data/pattern", "w");
92 for( j
= 0; j
< pattern_size
; j
++ ) {
93 for( i
= 0; i
< pattern_size
; i
++ )
94 fputc( rand() % alphabet
+ 1, pattern_fp
);
95 fputc( 10, pattern_fp
);
101 text_fp
= fopen("data/text", "w");
103 for( j
= 0; j
< text_size
; j
++ ){
104 for( i
= 0; i
< text_size
; i
++ )
105 fputc ( rand() % alphabet
+ 1, text_fp
);
106 fputc ( 10, text_fp
);