Error with recover.c cs50 program

hi i am doing cs50 and have an error with my code please can you find out what the error is?
recover.c

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

const int HEADER_SIZE = 4;
int counter = 0;
bool reading = false;

void parse(uint8_t buffer[], FILE  *ptr);

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

    FILE *file = fopen("card.raw", "r");
    if (file == NULL) {
        return 1;
    }
    uint8_t header[HEADER_SIZE];
    uint8_t buffer[512];
    while (fread(buffer, sizeof(uint8_t), 512, file) >= 512)
    {
        parse(buffer, file);
    }
    fclose(file);

}

void parse(uint8_t buffer[], FILE *ptr)
{
        uint8_t header[HEADER_SIZE];
        for (int i = 0; i < HEADER_SIZE; i++)
        {
            header[i] = buffer[i];
        }
        if ((header[0] == '0xff' && header[1] == '0xd8' && header[2] == '0xff' && (header[3] & '0xf0') == '0xe0') || reading == true)
        {
            char *filename = malloc(sizeof(char)*10);
            sprintf(filename, "%03i.jpeg", counter);
            FILE *img = fopen(filename, 'w');
            if (img == NULL){
                return 2;
            }
            fwrite(buffer, sizeof(uint8_t), 512, img);
            reading = true;
            counter++;
            free(filename);
        }
        else
        {
            reading = false;
        }
}

console

recover/ $ make recover
recover.c:45:41: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *' [-Werror,-Wint-conversion]
            FILE *img = fopen(filename, 'w');
                                        ^~~
/usr/include/stdio.h:259:30: note: passing argument to parameter '__modes' here
                    const char *__restrict __modes)
                                           ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
2 errors generated.
make: *** [<builtin>: recover] Error 1
recover/ $ 

hi this code is meant to recover jpeg images from a .raw file

I personally always asked my cs50 questions on their Reddit support forum. They also have active support on other apps too.

Here you used double quotes. Try using double quotes where you see the error.

1 Like

now i have many jpeg images without any content can anyone debug the updated program

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

const int HEADER_SIZE = 4;
int counter = 0;
bool reading = false;

int parse(uint8_t buffer[], FILE  *ptr);

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

    FILE *file = fopen(argv[1], "r");
    if (file == NULL) {
        return 1;
    }
    uint8_t header[HEADER_SIZE];
    uint8_t buffer[512];
    while (fread(buffer, sizeof(uint8_t), 512, file) >= 512)
    {
        parse(buffer, file);
    }
    fclose(file);

}

int parse(uint8_t buffer[], FILE *ptr)
{
        uint8_t header[HEADER_SIZE];
        for (int i = 0; i < HEADER_SIZE; i++)
        {
            header[i] = buffer[i];
        }
        if ((header[0] == 0xff && header[1] == 0xd8 && header[2] == 0xff && (header[3] & 0xf0) == 0xe0) || reading == true)
        {
            char *filename = malloc(sizeof(char)*10);
            sprintf(filename, "%03i.jpeg", counter);
            FILE *img = fopen(filename, "w");
            if (img == NULL){
                return 2;
            }
            fwrite(buffer, sizeof(uint8_t), 512, img);
            reading = true;
            counter++;
            free(filename);
            return 0;
        }
        else
        {
            reading = false;
            return 0;
        }
}

Can you say more about what’s happening?

1 Like

im getting a thousand jpeg files the first one is blank and the other files cannot be read

How are you opening one thousand jpeg files?

1 Like

on vs code it works for other images just not these ones

How are you opening one thousand jpeg files with this code?

1 Like

you can open jpeg files on vs code

You aren’t really answering my question. How is this code opening thousands of jpegs? It looks like your code only opens 4 images?