I want to read an image, say image1 as a string and convert it back as image2. Below is my code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int length;
FILE *image1,*image2;
image1= fopen("image1.jpg", "rb");
fseek(image1, 0, SEEK_END);
length= ftell(image1);
rewind(image1);
char file_data[length+1];
fread(file_data, length, 1, image1);
image2 = fopen ("image2.jpg", "wb");
fprintf (image2, "%s", file_data);
fclose(image1);
fclose(image2);
return 0;
}
However, the image2 that is getting created is not opening. How do I rectify this?