Below is my code for pset4 recover.c. I tried my best to write these code out but still having bunch of compiling errors. Could anyone give me some guide or just point out my incorrect points? Thanks in advance.
`
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
// open the memory file
FILE* raw = fopen("card.raw", "r");
FILE* buffer = fopen("buffer.txt", "w");
//FILE* a = fopen("a.txt", "w");
int count = 0;
char* jTitle;
FILE* img[count];
char* check = malloc(2 * 512);
while (fread(check, 512, 2, raw) == 2)
{
fseek(raw, -1024, SEEK_CUR);
char* block = malloc(512);
fread(block, 512 , 1, raw);
fwrite(block, 512, 1, buffer);
// check if the block is the start of jpg
int* head;
fread(head, sizeof(int), 1, buffer);
if (*head == ffd8ffe#)
{
count++;
// check if already opened a jpg file
if (jTitle != NULL)
{
fclose(img[count-1]);
sprintf(jTitle, "%03d.jpg", count);
FILE* img[count] = fopen(jTitle, "a");
fwrite(buffer, 512, 1 , img);
}
else
{
sprintf(jTitle, "%03d.jpg", count);
FILE* img[count] = fopen(jTitle, "a");
fwrite(buffer, 512, 1 , img);
}
}
else
{
if (jTitle != NULL)
{
fwrite(buffer, 512, 1, img);
}
}
}
free(check);
}
`