Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- int main(int argc, char *argv[])
- { int n=0;
- // ensure proper usage
- if (argc != 2)
- {
- fprintf(stderr, "Usage: ./copy infile outfile\n");
- return 1;
- }
- char *infile = argv[1];
- // open input file
- FILE *inptr = fopen(infile, "r");
- if (inptr == NULL)
- {
- fprintf(stderr, "Could not open %s.\n", infile);
- return 2;
- }
- int flag =0;
- uint8_t *buffer = malloc(512*sizeof(uint8_t));
- FILE *img;
- char *a = malloc(sizeof(uint8_t)); ;
- while (fread(buffer,1,512,inptr)==512)
- {
- if(((*buffer)==0xff&&(*buffer+1)==0xd8&&(*buffer+2)==0xff&&((*buffer+3) & 0xf0)==0xe0)&&flag==0)
- {
- sprintf(a,"%03i.jpg",n);
- n++;
- flag =1;
- img = fopen(a,"w");
- for(int x=0;x<512;x++)
- {
- fwrite(buffer,1,1,img);
- }
- if(((*buffer)==0xff&&(*buffer+1)==0xd8&&(*buffer+2)==0xff&&((*buffer+3) & 0xf0)==0xe0)&&flag==1)
- {
- fclose(img);
- sprintf(a,"%03i.jpg",n);
- n++;
- flag =1;
- FILE *img = fopen(a,"w");
- fwrite(buffer,512,1,img);
- }
- }
- else if(flag==1)
- {
- fwrite(buffer,512,1,img);
- }
- else
- break;
- }
- fclose(inptr);
- }
- OUTPUT
- $ make recover
- clang -fsanitize=integer -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wshadow recover.c -lcrypt -lcs50 -lm -o recover
- recover.c:44:23: error: declaration shadows a local variable [-Werror,-Wshadow]
- FILE *img = fopen(a,"w");
- ^
- recover.c:22:12: note: previous declaration is here
- FILE *img;
- ^
- 1 error generated.
- make: *** [recover] Error 1
- ~/workspace/recover/ $
Add Comment
Please, Sign In to add comment