#include "../myhead.h"
void *task(void *arg)
{
char a;
int count = 0;
FILE *fp2 = fopen("./mouse.bmp", "r");
perror("fopen2");
FILE *fp4 = fopen("../txt/8.bmp", "w");
perror("fopen4");
fseek(fp2, 0, SEEK_END);
int size = ftell(fp2);
fseek(fp2, size / 2, SEEK_SET);
fseek(fp4, size / 2, SEEK_SET);
while (count < size / 2)
{
if (fread(&a, sizeof(a), 1, fp2) != 1)
{
perror("fread");
}
if (fwrite(&a, sizeof(a), 1, fp4) != 1)
{
perror("fwrite");
}
count++;
}
if (size % 2 != 0)
{
fread(&a, sizeof(a), 1, fp2);
fwrite(&a, sizeof(a), 1, fp4);
}
}
int main(int argc, char const *argv[])
{
char b;
FILE *fp1 = fopen("./mouse.bmp", "r");
perror("fopen");
FILE *fp3 = fopen("../txt/8.bmp", "w");
perror("fopen3");
int count = 0;
fseek(fp1,0,SEEK_END);
int size = ftell(fp1);
fseek(fp1,0,SEEK_SET);
pthread_t tid;
if (pthread_create(&tid, NULL, task, NULL) != 0)
{
perror("pthread_create error");
exit(-1);
}
while (count < size / 2)
{
fread(&b, sizeof(b), 1, fp1);
fwrite(&b, sizeof(b), 1, fp3);
count++;
}
pthread_join(tid, NULL);
return 0;
}