File in binary form

I want to write data into the file in binary form.

I was trying using the mentioned below

FILE *fp = fopen("binaryoutput.rgb888", "ab+");

for(int m=0; m<height; m++)
   for (int n=0; n< width; n++)        
    temp = (pOutputImg+m*3+n*3); // here pOutputImg & temp is a pointer to a unsigned char  

I am able to get data which is strored at pOutputImg but not in binary form.

Can anyone guide me the correct step..

Thanks in advance


Replace fprintf() with fwrite().


fwrite(temp, sizeof(*temp), 1, fp);

The whole purpose of fprintf() is to format binary data as readable ascii ... the exact opposite of what you want. fwrite() is for directly writing binary data.

If this is a pixmap of rgb triplets, you can write the binary data with one line:

fwrite(pOutputImg, 3, height * width, fp);

Need Your Help

Setting sys properties in ant taskdef

java ant

i have a taskdef pointing to a class

TypeScript+SystemJS using JSON and Text plugins

javascript typescript amd typescript1.5 systemjs

Using TypeScript with SystemJS, how can I import a JSON file using plugin-json?