Hello again... I have a problem in a program i have made. This program generates int numbers and store them in a file. The program seems to work ok but the problem is that when i generate the random numbers and store them in the input.txt when i open the input.txt i only can see some strange symbols and not the actual numbers. Although in the screen when i run the program it seems ok and the numbers appears fine and i can see them. Can anyone tell me where is the problem and i can't see the numbers in the file i have created???
If is easier to you I am sending the code too, to tell me if there is a serious problem and i can not see the numbers in the file.
Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define LIMIT 1000
void main() {
FILE *fp ;
char str [67] ;
int i, N, random_number;
printf ( "Enter file name: " ) ; //Reads a file name from the user
scanf ( "%s", str ) ;
printf ( "Enter number of records: " ) ; //Reads how many numbers the user wants to have in the file
scanf ( "%d", &N ) ;
fp = fopen ( str, "wb" ) ; //Try to open the file
if ( fp == NULL ) {
printf ( "Unable to create file." ) ;
getch() ;
exit (0) ;
}
srand ( time(NULL) );
for ( i = 0 ; i < N ; i++ ) {
random_number = rand()%LIMIT; //Generates the random numbers
fwrite ( &random_number, sizeof ( int ), 1, fp ) ;//Write the numbers in the file
printf ( "%d\t", random_number) ; //Print the numbers
}
fclose (fp) ; //Close the file
}
Thank you.