#include int main(int argc, char** argv) { FILE* infile = fopen( "file.txt", "r" ); FILE* outfile = fopen( "file2.txt", "w" ); FILE* binary = fopen( "data.simp", "rb" ); if ( infile == 0 ) { /* Error happened in fopen! */ printf("Failed to open file.txt!\n"); /* TODO: close other files */ return 1; } /* flush the file buffer */ fflush(outfile); fflush(stdout); /* Let's Read from infile! */ int number = 0; fscanf( infile, "%d", &number ); /* similar to scanf */ /* fscanf( stdin, format, args... ) == scanf( format, args... ) */ /* To read a single int from a binary file: */ /* fread( data pointer, wordsize, length, FILE* ) */ fread( &number, sizeof(int), 1, binary ); fprintf( outfile, "%04d\n", number ); /* fprintf( stdout, format, args.. ) == printf( format, args...) */ /* fwrite( data pointer, wordsize, length, FILE* ) */ fwrite( &number, sizeof(int), 1, binary ); char c = fgetc( infile ); /* Get a single character from infile */ if ( c == EOF ) { /* c is the End-of-File character */ /* Works for Text Files (not binary Files!) */ printf("I'm out! No more data!\n"); } if ( feof( binary ) ) { /* I get here if binary is out of data! */ } FILE* appendify = fopen("file2.txt", "a"); /* append to existing data! */ fputc( outfile, c ); /* Write a single character to outfile */ /* Done with infile */ fclose(infile); fclose(outfile); fclose(binary); infile = 0; outfile = 0; binary = 0; return 0; }