Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Data File StructureRSS Feeds

Program that creates random numbers in a given file

Posted By: Raoul Fischer     Category: C Programming     Views: 7660

Program that creates random numbers in a given file.

Code for Program that creates random numbers in a given file in C Programming

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

void main( )
{
    FILE *fp ;
    char str [ 67 ] ;
    int i, noofr, j ;

    clrscr( ) ;

    printf ( "Enter file name: " ) ;
    scanf ( "%s", str ) ;

    printf ( "Enter number of records: " ) ;
    scanf ( "%d", &noofr ) ;

    fp = fopen ( str, "wb" ) ;
    if ( fp == NULL )
    {
        printf ( "Unable to create file." ) ;
        getch( ) ;
        exit ( 0 ) ;
    }

    randomize( ) ;

    for ( i = 0 ; i < noofr ; i++ )
    {
        j = random ( 1000 ) ;
        fwrite ( &j, sizeof ( int ), 1, fp ) ;
        printf ( "%d\t", j ) ;
    }

    fclose ( fp ) ;

    printf ( "\nFile is created. \nPress any key to continue." ) ;

    getch( ) ;
}
  
Share: 


Didn't find what you were looking for? Find more on Program that creates random numbers in a given file Or get search suggestion and latest updates.

Raoul Fischer
Raoul Fischer author of Program that creates random numbers in a given file is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!