/* NumbersToFile.c (c) Kari Laitinen http://www.naturalprogramming.com/ 2013-11-28 File created. 2013-11-28 Last modification. */ #include #include int main() { FILE *file_to_write ; file_to_write = fopen( "NumbersToFile_output.data", "wb" ) ; if ( file_to_write == 0 ) { printf( "\n Cannot open NumbersToFile_output.data" ) ; } else { int integer_to_file = 0x22 ; while ( integer_to_file < 0x77 ) { fwrite( (char*) &integer_to_file, 1, sizeof( int ), file_to_write ) ; integer_to_file = integer_to_file + 0x11 ; } short short_integer_to_file = 0x1234 ; double double_value_to_file = 1.2345 ; bool boolean_true_to_file = true ; bool boolean_false_to_file = false ; fwrite( (char*) &short_integer_to_file, 1, sizeof( short ), file_to_write ) ; fwrite( (char*) &double_value_to_file, 1, sizeof( double ), file_to_write ) ; fwrite( (char*) &boolean_true_to_file, 1, sizeof( bool ), file_to_write ) ; fwrite( (char*) &boolean_false_to_file, 1, sizeof( bool ), file_to_write ) ; char c_style_string_to_file[] = "aaAAbbBB" ; int string_length_to_file = strlen( c_style_string_to_file ) ; fwrite( (char*) &string_length_to_file, 1, sizeof( int ), file_to_write ) ; fwrite( c_style_string_to_file, 1, string_length_to_file, file_to_write ) ; char bytes_to_file[] = { 0x4B, 0x61, 0x72, 0x69 } ; fwrite( bytes_to_file, 1, 4, file_to_write ) ; fclose( file_to_write ) ; } }