Posts

Showing posts with the label External Sorting.

External Sorting.

External Sorting. #include "stdio.h" #include "conio.h" #include "stdlib.h" void shownums ( char * ) ; void split ( char * ) ; void sort ( char * ) ; void main( ) { char str[67] ; clrscr( ) ; printf ( "Enter file name: " ) ; scanf ( "%s", str ) ; printf ( "Numbers before sorting:\n" ) ; shownums ( str ) ; split ( str ) ; sort ( str ) ; printf ( "\nNumbers after sorting:\n" ) ; shownums ( str ) ; getch( ) ; } /* Displays the contents of file */ void shownums ( char *p ) { FILE *fp ; int i ; fp = fopen ( p, "rb" ) ; if ( fp == NULL ) { printf ( "Unable to open file." ) ; getch( ) ; exit ( 0 ) ; } while ( fread ( &i, sizeof ( int ), 1, fp ) != 0 ) printf ( "%d \t", i ) ; fclose ( fp ) ; } /* Splits the original file into two files */ void split ( char *p ) { FILE *fs, *ft ; ...