Could somebody tell how I can actually write the input and output to a disk file?
When I open the disk file, it only has the description, but not the data
Code:#include <stdio.h> #include <conio.h> #include <process.h> int main(void) { FILE *test2_file; int num; int no_bits; int reply = 0; test2_file = fopen ("decimal2binary.txt", "w"); fprintf (test2_file, "This is the content of the decimal2binary file."); do { system("cls"); printf("\n Welcome to the DECIMAL to BINARY program!"); printf("\nThis program accepts a decimal number and converts it into a "); printf("binary number.\nIt also states how many bits the number occupies."); printf("\n\nEnter a number: "); scanf("%d",&num); no_bits=count_bits(num); printf("The number of bits is %d",no_bits); bin_print(num,no_bits); printf("\n"); printf("Would you like to input another number (y/n): "); reply = getche(); if ((reply != 'n') && (reply != 'N')) { printf("\n\nTo terminate inputs you need to reply N or n -"); printf(" your reply was %c", reply); } } while ((reply == 'y') || (reply == 'Y')); fclose(test2_file); printf("\n\n"); printf("Bye friends!\n"); system("pause"); } count_bits(int n) { int i = 0; for (;n!=0; n = n >> 1) i++; return(i); } bin_print(int x, int n_bits) { int j; printf("\nno. %d in binary: ",x); for( j = n_bits - 1; j >= 0; j--) printf("%i",( x >> j ) & 01); }



LinkBack URL
About LinkBacks


