Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, char *argv[])
- {
- if (argc != 2)
- {
- printf("Incorrect usage\n");
- return 1;
- }
- FILE *file = fopen(argv[1], "r");
- int buffer[512];
- char filename[8];
- int jpg_counter = 0;
- FILE *img = NULL;
- while (fread(buffer, 512, 1, file) == 1)
- {
- if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] & 0xf0) == 0xe0)
- {
- if (jpg_counter == 0) //If this is the first jpg, then start writting the first file 000.jpg
- {
- sprintf(filename, "%03i.jpg", jpg_counter);
- img = fopen(filename, "w");
- fwrite (filename, 512, 1, img);
- }
- else //If i already found a jpg, then, close the previous file, increment jpg_counter and open a new file
- {
- fclose (img);
- jpg_counter ++;
- sprintf(filename, "%03i.jpg", jpg_counter);
- img = fopen(filename, "w");
- fwrite (filename, 512, 1, img);
- }
- }
- else
- {
- if (jpg_counter != 0 && img != NULL) //If it's not a start of a jpeg, then, If I already found a jpg and the image is open, keep writing
- {
- img = fopen(filename, "w");
- fwrite (filename, 512, 1, img);
- fclose (img);
- }
- }
- }
- fclose (file);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement