summaryrefslogtreecommitdiff
path: root/wk4/pset/recover
diff options
context:
space:
mode:
Diffstat (limited to 'wk4/pset/recover')
-rw-r--r--wk4/pset/recover/recover.c59
-rw-r--r--wk4/pset/recover/test.c11
2 files changed, 7 insertions, 63 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
- }
- }
-
-
-
-
-
- */
-
}
diff --git a/wk4/pset/recover/test.c b/wk4/pset/recover/test.c
deleted file mode 100644
index 30ddd9b..0000000
--- a/wk4/pset/recover/test.c
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <cs50.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-int main(int argc, char *argv[])
-{
- printf("%i\n", (int)(ceil(500000/512.0)));
-}