Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. int aparitii_Prob_3(char* template, int fd_target,int dim);
  2. void Problema3(int bits, int no_of_template, int fd_template, int fd_target){
  3. short int version;//testare versiune
  4. short int no_of_templates_categories;
  5. short int dimensions[no_of_templates_categories];
  6. short int no_of_templates[no_of_templates_categories];
  7. int offset[no_of_templates_categories];
  8. int dummy;
  9. if(read(fd_template,&version,2)<0){
  10. perror("Mesaj 1");
  11. exit(1);
  12. }
  13. if(read(fd_template,&no_of_templates_categories,2)<0){
  14. perror("Mesaj 2");
  15. exit(1);
  16. }
  17. for(int i=0;i<no_of_templates_categories;i++)
  18. {
  19. if(read(fd_template,&dimensions[i],2)<0){
  20. perror("Mesaj 3");
  21. exit(1);
  22. }
  23. if(read(fd_template,&no_of_templates[i],2)<0){
  24. perror("Mesaj 4");
  25. exit(1);
  26. }
  27. if(read(fd_template,&offset[i],4)<0){
  28. perror("Mesaj 5");
  29. exit(1);
  30. }
  31. }
  32. /*
  33. printf("Versiunea este %d\n", version);
  34. printf("Numarul de categorii de sabloane este %d\n", no_of_templates_categories);
  35. for(int i=0;i<no_of_templates_categories;i++)
  36. {
  37. printf("Categoria cu no %d are caracteristicile: dimensiunea %d , numarul de sabloane %d, offsetul %d\n",i+1,dimensions[i],no_of_templates[i],offset[i]);
  38. }
  39. */
  40. int position=-1;
  41. for(int i=0;i<no_of_templates_categories;i++)
  42. {
  43. if(bits==dimensions[i]){
  44. position=i;
  45. break;
  46. }
  47. }
  48. if(position!=-1){
  49. lseek(fd_template, (no_of_template-1)*(dimensions[position]/8) + offset[position] , SEEK_SET);
  50. }
  51. else {
  52. perror("Nu imi place");
  53. }
  54. char to_read_template[dimensions[position]/8];
  55. if(read(fd_template,&to_read_template,dimensions[position]/8)<0){
  56. perror("Mesaj 6");
  57. exit(1);
  58. }
  59. //printf("%s\n", to_read_template);
  60. for(int i=0;i<dimensions[position]/8;i++){
  61. printBits1(1,&to_read_template[i]);
  62. }
  63. int nr_aparitii=aparitii_Prob_3(to_read_template,fd_target,dimensions[position]/8);
  64. printf("%d", nr_aparitii);
  65. //printf("%d",no_of_templates_categories);
  66. //printf("%d", version);
  67. // if() testare version
  68. }
  69. int aparitii_Prob_3(char* template, int fd_target, int dim)
  70. {
  71. int nr_ap=0;
  72. char template_copy[dim];
  73. char buffer[512];
  74. int dim_copy=0;
  75. while(read(fd_target,&buffer,512)!=0){
  76. for(int i=0;i<512;i++)
  77. {
  78. template_copy[dim_copy]=buffer[i];
  79. dim_copy++;
  80. if(dim_copy==dim){
  81.  
  82. if(strcmp(template,template_copy)==0){
  83. nr_ap++;
  84. }
  85. dim_copy--;
  86. }
  87. }
  88.  
  89.  
  90. }
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement