diff options
Diffstat (limited to 'wk4/pset/recover/recover.c')
-rw-r--r-- | wk4/pset/recover/recover.c | 59 |
1 files changed, 7 insertions, 52 deletions
diff --git a/wk4/pset/recover/recover.c b/wk4/pset/recover/recover.c index 1f96528..c10d032 100644 --- a/wk4/pset/recover/recover.c +++ b/wk4/pset/recover/recover.c @@ -1,14 +1,15 @@ #include <cs50.h> #include <ctype.h> +#include <math.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <math.h> int main(int argc, char *argv[]) { - if (argc != 2) { + if (argc != 2) + { printf("Usage: ./recover infile\n"); return 1; } @@ -27,16 +28,11 @@ int main(int argc, char *argv[]) char name[8]; // restoring jpegs - while(fread(buffer, 1, 512, card) == 512) + while (fread(buffer, 1, 512, card) == 512) { // check if this is a new picture - if ( - buffer[0] == 0xff && - buffer[1] == 0xd8 && - buffer[2] == 0xff && - buffer[3] >= 0xe0 && - buffer[3] <= 0xef - ) + if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && buffer[3] >= 0xe0 && + buffer[3] <= 0xef) { // this is a jpeg, make a new file from it files++; @@ -45,7 +41,7 @@ int main(int argc, char *argv[]) fwrite(buffer, 1, 512, point); fclose(point); } - else if(files >= 0) // if it is part of a previous picture, add to it + else if (files >= 0) // if it is part of a previous picture, add to it { FILE *point = fopen(name, "a"); fwrite(buffer, 1, 512, point); @@ -53,45 +49,4 @@ int main(int argc, char *argv[]) } } fclose(card); - - /* - files = 0 - for (file length) - { - if (first 3 bytes are 0xff 0xd8 0xff AND 4th byte is 0xe* (* denotes anything)) - fread(ptr, ) - { - this is a photo; remember the pointer (call it point) - int photolength = 0; - // look through the blocks ahead of this one for a new photo - for (file length left) - { - photolength++; - if (first 3 bytes are 0xff 0xd8 0xff AND 4th byte is 0xe* (* denotes anything)) - { - // this is the photo length - break - } - } - filename = files.jpg - files++ - Open output file with name (filename) - - // make buffer space to store the data - uint32_t data[photolength][16]; - // read the photo to data in blocks of 32 bits - fread(&data, sizeof(uint8_t), 16 * photolength, card); - // write the photo from data - fwrite(&data, sizeof(uint8_t), 16 * photolength, point); - // Close the photo file - // repeat this process for other photos - } - } - - - - - - */ - } |