Is it possible to fwrite in binary with two different types at the same function?

149 Views Asked by At

Hello I have to make a program that involves writing a matrix in a binary file, but it has to have a space between every number written. Also the first fwrite has to have the size of the lines and columns. So instead of making something like:

fwrite( &n, sizeof( int ), 1, fw ); 
fwrite( &space, sizeof( char ), 1, fw ); 
fwrite( &m, sizeof( int ), 1, fw );

or

space = ' ';
fwrite( &temp, sizeof( int ), 1, fw );
fwrite( &sapce, sizeof( char ), 1, fw );

I wanted to see if something like this, would be possible.

fwrite( "&n &m", 2*sizeof( int ) + sizeof( char ), 1, fw );

fwrite( "&n ", sizeof( int ) + sizeof( char ), 1, fw );
1

There are 1 best solutions below

0
On

may be you can try this:

    char a[256];
    sprintf(a, "%d %d", n, m);
    fwrite( a, strlen(a), 1, fw );