I've tried some different values with fread() an with fwrite() but had no new results. On the right in some pictures appears, like a column, part of the image that should be at the left, and in some pictures,on the beginning of it (the superior left corner) appears some errors like there is an error with the stream of data. Some pictures have color problems and some are perfect. I can get all the fifty. Some one can imagine what can cause this type of error? some code below:

[EDIT: irrelevant code removed.]

char *picture_name[8];

// Loop until gets all the photos from the forensic image
    while (!feof(file))
        fread(buffer, 4, 128, file);

            // Give name to pictures and control the fclose() function
            sprintf(*picture_name, "%03i.jpg", picture_number);
            image = fopen(*picture_name, "w");

    // Close last picture

I've changed a little this code since the start but continues given some errors.

  • Not without seeing some code – Cliff B Sep 4 '20 at 0:51

I'm guessing that memory is getting stepped on. First, was memory allocated for picture_name? How much memory?

Next, the fread is being executed, the data processed, and only then is a check for EOF done. In other words, "ready, shoot, aim."


After reviewing the full code elsewhere, the problem lies in the declaration:

char *picture_name[8];

This creates an array of 8 pointers to chars, not an array of 8 chars. This is causing serious memory issues when the program executes and is stepping on data.

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

  • I'm trying not to put all the code here to not give a spoiler of the pset. The memory for picture name is ok. I've already corrected this point and nothing was improved. – Maurício Mota Sep 4 '20 at 2:58
  • EOF check is for file that is: FILE *file = fopen(argv[1], "r"); – Maurício Mota Sep 4 '20 at 2:59
  • EOF check is for 'file' that is: FILE *file = fopen(argv[1], "r"); file receives the raw image and the check is being done to reach the end of the raw image in file. The problem occurs since the first picture. I guess if this was the problem it would occur at the last picture. What I observed in the pictures was a fail in the first lines on top left as there was a corruption of the first bytes writen in the picture. – Maurício Mota Sep 4 '20 at 3:09
  • How is buffer declared? What type? Also, post the declaration for picture_name and the malloc for it. – Cliff B Sep 4 '20 at 3:30
  • typedef uint8_t BYTE; BYTE buffer[512]; char *picture_name[8]; – Maurício Mota Sep 4 '20 at 3:38

You must log in to answer this question.

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