0

Because I can't get debug50 to help me out, I don't know where to start to debug this program. I think I have an infinite loop somewhere, but I'm not sure. Any help to get me started on right path would help greatly. Thanks.

BYTE buffer[FAT];
    //fread first 4 bytes of file
    int counter = 0;
    //file name for new jpg files
    FILE *image = NULL;
    while (fread(buffer, FAT, 1, f))
    {
        //find jpeg header
        if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] & 0xf0) == 0xe0)
        {
            //create a new, ###.jpeg file
            char jpgfile[8];
            sprintf(jpgfile, "%03i.jpg", counter);
            if (counter != 0)
            {
                fclose(image);
            }
            counter++;
            image = fopen(jpgfile, "w");
            if (image == NULL)
            {
                printf("File not supported\n");
                return 3;
            }
        }
        else if (counter != 0)
        {
            //if header found, write 512 groups to the new jpeg file until next header found
            do
            {
                fwrite(&buffer, sizeof(buffer), 1, image);
            }
            while (buffer[0] != 0xff && buffer[1] != 0xd8 && buffer[2] != 0xff && (buffer[3] & 0xf0) != 0xe0);
        }
        else if (feof(f))
        {
            return 0;
        }
    }
    //close any open files
    fclose(f);
    fclose(image);
0

In case anyone wanted to know... Debug50 started working again and I figured out I didn't need the second clause for buffer[0] to buffer[3]. The first one took care of everything, the second one put me in an infinite loop.

All is working now!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .