Just to get you started, you can do this. However, be careful not to overflow your buffers, as this below isn't the best way to do this, but it gives you and idea. It uses a fixed array, but I didn't think your question concerned memory allocation.
Anyway, this simply saves everything into a buffer, then prints the buffer.
Code:
#include <stdio.h>
#define MAX_BUF 2048
int main ()
{
FILE *file = fopen( "test.c", "r" );
char array[ MAX_BUF ]; //a buffer to store up to 2048 characters
if ( file == 0 )
{
printf( "Could not open file\n" );
}
else
{
int x;
int num = 0;
while ( ( x = fgetc( file ) ) != EOF )
{
// printf( "%c", x );
// if there is rat least room for an ending NULL byte, then store the character
if( num < (MAX_BUF-1) ) {
array[num++] = x;
}
}
}
//now dump the buffer to the stdout
printf("other buffer: \n%s", array );
printf("\n");
fclose( file );
}
Hope this gets you going. Then from the looks of it your next task is to read that buffer back into another file. I'll leave you to it.