I have had some segmentation fault and errors in this code before that was fixed with you guys help (thanks Cliff B!). After fixing everything that I could, and thinking that everything now makes sense to me, my program still doesn't give me any jpgs! When I actually compiles the program, nothing actually shows up. I have used gdb to try to check it but it does seem to run properly so I have no clue what's going on. Can someone please help me point out what I'm doing wrong?
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
int main(int argc, char* argv[])
{
// open memory file
FILE* inptr = fopen("card.raw", "r");
//assigning stuff
char jpgname [8];
int c = 0;
uint8_t buffer[512];
int b = 0;
if (inptr == NULL)
{
printf("Could not open file");
return 1;
}
FILE * outptr = NULL;
while(fread(buffer, 512, 1, inptr) == 1)
{
if( (buffer[0] == 0xff && buffer [1] == 0xd8 && buffer [2] == 0xff && buffer [3] == 0xe0 )|| (buffer[0] == 0xff && buffer [1] == 0xd8 && buffer [2] == 0xff && buffer [3] == 0xe1 ))
{
if (outptr != NULL)
{
fclose(outptr);
}
sprintf (jpgname, "%d.jpg", c);
FILE * outptr = fopen(jpgname, "w");
fwrite (&buffer,512,1,outptr);
b++;
}
else if(b>0)
{
fwrite (&buffer,512,1,outptr);
}
return 0;
}
}