i have pointer to data buffer.
when i write PPM image using string (ASCII), it's written successfully without any distortion.
https://i.stack.imgur.com/TYAFY.png
but when i do the same thing but write binary data instead it gets distorted. https://i.stack.imgur.com/aaL72.png
I'v spent hours and i still don't know what is the problem. this is the code for the string writing
FILE *f;
int i;
f = fopen(filename,"w");
if (f == NULL) {
printf("cant open the file \n");
}
fprintf(f, "P3\n%d %d\n%d\n", xsize, ysize, 255);
for (i = 0; i < ysize * xsize * 3; i++){
fprintf(f, "%u\n", buf[i]);
}
fclose(f);
this is the code for the binary writing
FILE *f;
int i;
f = fopen(filename,"w");
if (f == NULL) {
printf("cant open the file \n");
}
fprintf(f, "P6\n%d %d\n%d\n", xsize, ysize, 255);
for (i = 0; i < ysize * xsize * 3; i++){
fwrite(buf + i, 1, 1, f);
}
fclose(f);
please help!