Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int aparitii_Prob_3(char* template, int fd_target,int dim);
- void Problema3(int bits, int no_of_template, int fd_template, int fd_target){
- short int version;//testare versiune
- short int no_of_templates_categories;
- short int dimensions[no_of_templates_categories];
- short int no_of_templates[no_of_templates_categories];
- int offset[no_of_templates_categories];
- int dummy;
- if(read(fd_template,&version,2)<0){
- perror("Mesaj 1");
- exit(1);
- }
- if(read(fd_template,&no_of_templates_categories,2)<0){
- perror("Mesaj 2");
- exit(1);
- }
- for(int i=0;i<no_of_templates_categories;i++)
- {
- if(read(fd_template,&dimensions[i],2)<0){
- perror("Mesaj 3");
- exit(1);
- }
- if(read(fd_template,&no_of_templates[i],2)<0){
- perror("Mesaj 4");
- exit(1);
- }
- if(read(fd_template,&offset[i],4)<0){
- perror("Mesaj 5");
- exit(1);
- }
- }
- /*
- printf("Versiunea este %d\n", version);
- printf("Numarul de categorii de sabloane este %d\n", no_of_templates_categories);
- for(int i=0;i<no_of_templates_categories;i++)
- {
- 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]);
- }
- */
- int position=-1;
- for(int i=0;i<no_of_templates_categories;i++)
- {
- if(bits==dimensions[i]){
- position=i;
- break;
- }
- }
- if(position!=-1){
- lseek(fd_template, (no_of_template-1)*(dimensions[position]/8) + offset[position] , SEEK_SET);
- }
- else {
- perror("Nu imi place");
- }
- char to_read_template[dimensions[position]/8];
- if(read(fd_template,&to_read_template,dimensions[position]/8)<0){
- perror("Mesaj 6");
- exit(1);
- }
- //printf("%s\n", to_read_template);
- for(int i=0;i<dimensions[position]/8;i++){
- printBits1(1,&to_read_template[i]);
- }
- int nr_aparitii=aparitii_Prob_3(to_read_template,fd_target,dimensions[position]/8);
- printf("%d", nr_aparitii);
- //printf("%d",no_of_templates_categories);
- //printf("%d", version);
- // if() testare version
- }
- int aparitii_Prob_3(char* template, int fd_target, int dim)
- {
- int nr_ap=0;
- char template_copy[dim];
- char buffer[512];
- int dim_copy=0;
- while(read(fd_target,&buffer,512)!=0){
- for(int i=0;i<512;i++)
- {
- template_copy[dim_copy]=buffer[i];
- dim_copy++;
- if(dim_copy==dim){
- if(strcmp(template,template_copy)==0){
- nr_ap++;
- }
- dim_copy--;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement