0

As the title says, the code won't compile, it keeps giving an error that says "use of undeclared label 'buff' which is referring to line 46. I'm not sure why it says that when i did in fact stated buff(line 37). Any idea as to why it's doing that or what i'm doing wrong here? Thanks for your response. Here's my code: https://gist.github.com/6e9bfa3282645ac1bac2953227d935e9

*
 * Recovers JPEGs from a forensic image.
 */
#include <stdio.h>
#include <stdint.h>

// prevent magic numbers
#define BLOCKSIZE 512

typedef uint8_t BYTE;

int main(void)
{
    // open memory card
    FILE* fp = fopen("card.raw", "r");

    // check file permission
    if (fp == NULL)
    {
        fclose(fp);
        printf("Unable to retrieve file from card.raw\n");
        return 1;
    }

    // create a char to name new image files
    char iname[8];

    // set a counter
    int counter = 0;

    // set a buffer of 512 bytes
    BYTE buff[BLOCKSIZE];

    // open output file
    FILE* outfile = NULL;

    // repeat until the end
    while (!feof(fp))
    {
        // find the start of the jpg
        if (buff[0] == 0xff && buff[1] == 0xd8 && buff[2] == 0xff && (buff[3] == 0xe0 || && buff[3] == 0xe1))
        {
            // if an outfile is open, close it
            if (outfile != NULL)
            {
                fclose(outfile);
            }

            // label files with three digits
            sprintf(iname, "%03d.jpg", counter);

            // open new file with name given by sprinft
            outfile = fopen(iname, "w");

            counter++;

            if (NULL == outfile)
            {
                printf("Couldn't open %s.\n", iname);
                return 1;
            }

            fwrite(buff, sizeof(buff), 1, outfile);

        }
        else if (counter > 0)
        {
            fwrite(buff, sizeof(buff), 1, outfile);
        }

        fwrite(buff, sizeof(buff), 1, fp);
    }

    // close file
    fclose(fp);

    // that's all folks
    return 0;
}
0

I can understand why you're having trouble finding the problem. It looks like a problem with buff and with parentheses, but it isn't. The compiler doesn't see it because, well, compilers are dumb! The problem lies in this line:

    if (buff[0] == 0xff && buff[1] == 0xd8 && buff[2] == 0xff 
               && (buff[3] == 0xe0 || && buff[3] == 0xe1))

Look closely at the subclause:

buff[3] == 0xe0 || && buff[3] == 0xe1

See anything wrong? It this an "and" or an "or" clause? ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • I feel so stupid for not even noticing it ahaha, thanks a lot man – Yekini Charles Nov 28 '16 at 17:15

You must log in to answer this question.

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