I can find the beginning of the 50 files. I am creating the files and I am writing to them.I suspect things go wrong after the first 512 bytes. When I open in hexcode I cannot see the signature of a jpg so I suppose it is somehow overwritten. I just don't see what is wrong with my code. I chose "a" instead of "w" so that I can append and I'm not getting any error message. When I try to open a file I get "unsupported format"(no signature). What is that I do wrong? (I got five out of six criteria right with a previous version but I would like to understand what I'm doing, this trial and error thing is driving me crazy).
``
typedef uint8_t BYTE;
int main(int argc, char *argv[])
{
if(argc != 2) {
fprintf(stderr, "Please enter one single file name");
return 1;
}
char *fotoFile = argv[1];
BYTE writeImage[512] = {0};
char name[7];
int tekst = 0;
FILE* inptr = fopen(fotoFile, "r");
if (inptr == NULL)
{
fprintf(stderr, "Could not open %s.\n", fotoFile);
return 2;
}
FILE* outptr = fopen(name, "a");
if (outptr == NULL)
{
fclose(inptr);
fprintf(stderr, "Could not create %s.\n", name);
return 3;
}
int stop = 0;
int einde = 0;
while(einde == 0) {
fread(writeImage, 512, 1, inptr);
if(!feof(inptr)) {
if (writeImage[0] == 0xFF && writeImage[1] == 0xd8 && writeImage[2] == 0xFF)
{
if(writeImage[3] > 223 && writeImage[3] < 240)
{
sprintf(name, "%03i.jpg", tekst);
tekst++;
fclose(outptr);
outptr = fopen(name, "a");
fwrite(writeImage, 512, 1, outptr);
if (stop == 0)
{
stop = 1;
}
}
}
if(stop == 1)
{
if (writeImage[0] != 0xFF && writeImage[1] != 0xd8 && writeImage[2] != 0xFF)
{
if(writeImage[3] < 224 || writeImage[3] > 239)
{
fwrite(writeImage, 512, 1, outptr);
}
}
}
}
if(feof(inptr))
{
einde = 1;
fclose(inptr);
}
}
}``