Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.83 KB | None | 0 0
  1. #include "LCS.h"
  2.  
  3.  
  4. int main(int argc, char * argv[])
  5. {
  6.  
  7.     /*
  8.     if (argc < 3) {
  9.         printf("Incorret number of arguments!\n");
  10.         exit(1);
  11.     }
  12.     printf("argc = %d\n", argc);
  13.     for (int i=1; i<argc; i++) {
  14.         fputs(argv[i], stdout);
  15.         printf("\n");
  16.     }
  17.     */
  18.  
  19.  
  20.     //Creating struct variables to store the files
  21.     struct file file_1, file_2;
  22.     //Opening the files
  23.     file_1.content = fopen("file21.ll", "r");
  24.     file_2.content = fopen("file22.ll", "r");
  25.     //Returns error if some file fails to open
  26.     if (file_1.content == NULL) {
  27.         perror("Error opening file\n");
  28.     }
  29.     if (file_2.content == NULL) {
  30.         perror("Error opening file\n");
  31.     }
  32.     //Uses the function to format input for file_1 and file_2
  33.     format_input (&file_1);
  34.     format_input (&file_2);
  35.     //Uses the function to return the lcs_matrix
  36.     int ** algorithm_matrix = lcs_matrix(&file_1, &file_2);
  37.     //Creates a int variable that will store the size of the lcs
  38.     int lcs_size = 0;
  39.     //Uses the function to return the LCS
  40.     char ** common_code = get_common_subsequence (&file_1, &file_2, algorithm_matrix, &lcs_size);
  41.     //Prints the LCS
  42.     for (int i =0; i<lcs_size; i++)
  43.     {
  44.         fputs(common_code[i], stdout);
  45.     }
  46.     printf("\n");
  47.     //Uses functions to free the dynamically allocated elements
  48.     free_lcs_matrix(algorithm_matrix, file_1, file_2);
  49.     free_struct_file (file_1);
  50.     free_struct_file (file_2);
  51.     free_lcs(common_code, lcs_size);
  52.  
  53.     //CLOSES THE FILES
  54.  
  55.     int close_1 = fclose(file_1.content);
  56.     if (close_1 != 0)
  57.     {
  58.         printf("error closing the file\n");
  59.     }
  60.  
  61.     int close_2 = fclose(file_2.content);
  62.     if (close_2 != 0)
  63.     {
  64.         printf("error closing the file\n");
  65.     }
  66.  
  67.  
  68.     system("pause");
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement