Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "LCS.h"
- int main(int argc, char * argv[])
- {
- /*
- if (argc < 3) {
- printf("Incorret number of arguments!\n");
- exit(1);
- }
- printf("argc = %d\n", argc);
- for (int i=1; i<argc; i++) {
- fputs(argv[i], stdout);
- printf("\n");
- }
- */
- //Creating struct variables to store the files
- struct file file_1, file_2;
- //Opening the files
- file_1.content = fopen("file21.ll", "r");
- file_2.content = fopen("file22.ll", "r");
- //Returns error if some file fails to open
- if (file_1.content == NULL) {
- perror("Error opening file\n");
- }
- if (file_2.content == NULL) {
- perror("Error opening file\n");
- }
- //Uses the function to format input for file_1 and file_2
- format_input (&file_1);
- format_input (&file_2);
- //Uses the function to return the lcs_matrix
- int ** algorithm_matrix = lcs_matrix(&file_1, &file_2);
- //Creates a int variable that will store the size of the lcs
- int lcs_size = 0;
- //Uses the function to return the LCS
- char ** common_code = get_common_subsequence (&file_1, &file_2, algorithm_matrix, &lcs_size);
- //Prints the LCS
- for (int i =0; i<lcs_size; i++)
- {
- fputs(common_code[i], stdout);
- }
- printf("\n");
- //Uses functions to free the dynamically allocated elements
- free_lcs_matrix(algorithm_matrix, file_1, file_2);
- free_struct_file (file_1);
- free_struct_file (file_2);
- free_lcs(common_code, lcs_size);
- //CLOSES THE FILES
- int close_1 = fclose(file_1.content);
- if (close_1 != 0)
- {
- printf("error closing the file\n");
- }
- int close_2 = fclose(file_2.content);
- if (close_2 != 0)
- {
- printf("error closing the file\n");
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement