I'm not sure where I went wrong with my code. Am I using fread and fwrite correctly? Thank you in advance!!
//opens the file
FILE *f = fopen(argv[1], "r");
//if the file contains nothing, return 1
if (f == NULL)
{
printf("Error. Could not open file");
fclose(f);
return 1;
}
//variable to keep track of the number of JPEG's opened
int num_jpeg = -1;
//creates a buffer that stores
BYTE *byee = malloc(512);
//Returns/stores 512 bytes from file
fread(byee, 512, 1, f);
//create char and temporary jpeg file
FILE *img = NULL;
while (fread(byee, 512, 1, f) == 1)
{
if (byee[0] == 0xff && byee[1] == 0xd8 && byee[2] == 0xff && (byee[3] & 0xf0) == 0xe0)
{
//creates a numbering for the amount of jpeg's opened
num_jpeg++;
//converts idk into a jpeg file basically
char idk[8];
sprintf(idk, "%3i.jpg", num_jpeg);
if (num_jpeg <= 0)
{
//opens idk jpeg file
img = fopen(idk, "w");
}
else
{
fclose(img);
img = fopen(idk, "w");
}
//writes byee into img
fwrite(&byee, 512, 1, img);
}
}
//frees memory
free(byee);
}