Not actually sure what is wrong with my code but it doesn't end when it's executed. I tried adding return 0 so it would end but it's not working.
code:
#include <stdio.h>
#include <stdint.h>
typedef uint8_t BYTE;
int main(int argc, char *argv[])
{
char *f_name;
int image_count = 0;
if (argc != 2)
{
printf("Usage: ./img\n");
return 1;
}
//input file
FILE *source = fopen(argv[1], "r");
if (source == NULL)
{
return 1;
}
//output file
FILE *destination = fopen(f_name, "w");
destination = NULL;
//buffer
BYTE buffer[512];
//check for jpeg
if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] & 0xf0) == 0xe0)
{
while(fread(buffer, sizeof(BYTE), 512, source))
{
image_count ++;
if (destination != NULL)
{
fclose(destination);
}
fwrite(buffer, sizeof(BYTE), 512, destination);
sprintf(destination, "%i", f_count);
}
}
fclose(source);
fclose(destination);
return 0;
}