CS50恢复 - 恢复的图像不匹配
我在CS50课程中的第4周,恢复问题。我的代码恢复了50个看上去对我的JPG,我找不到我的错误,我不知道该怎么办。当我使用check50时,它返回:
:) recover.c exists.
:) recover.c compiles.
:) handles lack of forensic image
:( recovers 000.jpg correctly
recovered image does not match
:( recovers middle images correctly
recovered image does not match
:( recovers 049.jpg correctly
recovered image does not match
代码:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
const int BLOCK_SIZE = 512;
typedef uint8_t BYTE;
int main(int argc, char *argv[])
{
if (argc != 2)
{
printf("Usage: ./recover IMAGE\n");
return 1;
}
FILE *raw_file = fopen(argv[1],"r");
if (raw_file == NULL)
{
printf("The image cannot be opened");
return 1;
}
//buffer for storing 512 bytes of memory for cheking if there is jpg
BYTE buffer[512];
//variable that remember if i alredy created one file
bool alredycreated = false;
//variable of file
int intfilename = 0;
FILE* file = NULL;
char filename[8];
while (fread(buffer, 1, BLOCK_SIZE, raw_file) == BLOCK_SIZE)
{
if (buffer[0] == 0xff)
{
if (buffer[1] == 0xd8)
{
if (buffer[2] == 0xff)
{
if (buffer[3] >= 0xe0 && buffer[3] <= 0xef)
{
if (alredycreated == true)
{
fclose(file);
}
sprintf(filename, "%03i.jpg",intfilename);
file = fopen(filename, "wb");
fwrite(&buffer, BLOCK_SIZE, 1, file);
alredycreated = true;
intfilename = intfilename + 1;
}
}
}
}
else if (alredycreated == true)
{
fwrite(&buffer, BLOCK_SIZE, 1, file);
}
}
fclose(raw_file);
}
Sorry for my english i am still learning english too.
I am in week 4 in CS50 course and I'm having problems with recover. My code recovers 50 jpgs that look right to me, and I can't find my mistake and I don't know what I'm supposed to do. When I use check50 it returns:
:) recover.c exists.
:) recover.c compiles.
:) handles lack of forensic image
:( recovers 000.jpg correctly
recovered image does not match
:( recovers middle images correctly
recovered image does not match
:( recovers 049.jpg correctly
recovered image does not match
Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
const int BLOCK_SIZE = 512;
typedef uint8_t BYTE;
int main(int argc, char *argv[])
{
if (argc != 2)
{
printf("Usage: ./recover IMAGE\n");
return 1;
}
FILE *raw_file = fopen(argv[1],"r");
if (raw_file == NULL)
{
printf("The image cannot be opened");
return 1;
}
//buffer for storing 512 bytes of memory for cheking if there is jpg
BYTE buffer[512];
//variable that remember if i alredy created one file
bool alredycreated = false;
//variable of file
int intfilename = 0;
FILE* file = NULL;
char filename[8];
while (fread(buffer, 1, BLOCK_SIZE, raw_file) == BLOCK_SIZE)
{
if (buffer[0] == 0xff)
{
if (buffer[1] == 0xd8)
{
if (buffer[2] == 0xff)
{
if (buffer[3] >= 0xe0 && buffer[3] <= 0xef)
{
if (alredycreated == true)
{
fclose(file);
}
sprintf(filename, "%03i.jpg",intfilename);
file = fopen(filename, "wb");
fwrite(&buffer, BLOCK_SIZE, 1, file);
alredycreated = true;
intfilename = intfilename + 1;
}
}
}
}
else if (alredycreated == true)
{
fwrite(&buffer, BLOCK_SIZE, 1, file);
}
}
fclose(raw_file);
}
Sorry for my english i am still learning english too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论