0

EDIT: I posted this 17 days ago please help.

Heres my code and it wud be great if someone cud help A.S.A.P. thankyou!

#include <stdio.h>
#include <stdlib.h>
#include<stdint.h>

#define BLOCKSIZE 512

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        printf("Usage: ./recover image\n");
    }
    return 1;

    FILE *infile = fopen(argv[1], "r");
    if (infile == NULL)
    {
        printf("Cannot open file\n");
    }
    return 1;

    const char *buffer[BLOCKSIZE];
    int jpg_count = 0;
    int jpg_found = 0;
    FILE* image = NULL;

    for (int i = 0; fread (buffer, BLOCKSIZE, 1, infile) < 1; i++)
    {
        if ((*buffer[0] == 0xff) && (*buffer[1] == 0xd8) && (*buffer[2] == 0xff) && ((*buffer[3] & 0xf0) == 0xe0))
        {
            jpg_found = 1;
            if (jpg_found == 1)
            {
                fclose(image);
            }
            else
            {
                jpg_found = -1;
            }
        }
        else if (jpg_found == 1)
        {
            char *filename;
            sprintf (filename, "%03i.jpg", jpg_count);
            image = fopen (*buffer, "a");
            jpg_count++;
            fwrite(&buffer, BLOCKSIZE, 1, image);
        }
    }
    fclose (infile);
    return 0;
}

CS50 says:

:( recovers 000.jpg correctly expected exit code 0, not 1

:( recovers middle images correctly expected exit code 0, not 1

:( recovers 049.jpg correctly expected exit code 0, not 1

4
  • 1
    Can't really help you if you just say that check50 doesn't satisfy then paste the code – Ojou Nii May 20 '20 at 13:57
  • @OjouNii i meant its not working, the code isnt recovering the images, I'll edit that – ammar79797 May 21 '20 at 11:34
  • Do you recover any images like you recover all the images but all of them seem to have problems, or are you not recovering any at all. – Ojou Nii May 21 '20 at 12:23
  • @OjouNii not recovering at all – ammar79797 May 21 '20 at 19:41

You must log in to answer this question.

Browse other questions tagged .