I want to count the 1kb blocks of 2 files and print out the number of identical blocks of these 2 files. I tried to read with fread 1kb blocks but when I tried to compare them I got stuck. I tried to compare the 1 kb blocks with strcmp but that won't work because strcmp is expecting a const char*, is there a way to convert a size_t to a const char*? or is there a better way to compare the blocks? So fare I wrote this:
#include <stdio.h>
#include <string.h>
int main()
{
FILE *fin;
FILE *fin2;
char block[1024];
char block2[1024];
int result;
int count=0;
int count_b_file1=0;
int count_b_file2=0;
fin=fopen("file1","r");
fin2=fopen("file2","r");
size_t s_file1;
size_t s_file2;
while( (! feof(fin)) && (! feof(fin2))){
s_file1=fread(block,1,sizeof(block),fin);
count_b_file1=count_b_file1+1;
s_file2=fread(block2,1,sizeof(block2),fin2);
count_b_file2=count_b_file2+1;
result=strcmp(s_file1,s_file2);
if (result==0){
count=count+1;
}
}
fclose(fin);
fclose(fin2);
return 0;
}