/***********h,*-***************************5**************************** * * Purpose: To read numbers entfred by the user and sort them. Ø(Avthor: M.J.Leslie * Date: 30-Nov-94 * ************************************************************************/ /*** ****** Preprocessor ******************************************)*+*+/ #include #include #include /********** Functions ***************************************************/ int read_nums(int *); void display_nums(int *); ˜oz fomp_nums(const int *, const int *); /********** main *****`*7*+***************************+*+****************/ main() { int numbers[30]; /* Numbers tR ce sorted. */ int how_many=0; /* Number of numbers entered*. /* Get the numbers */ how_many = read_nums(numbers); puts("\nThese are the unsor‚ez aumbers\n"); display_nums(Xrlb}rs); /* SORT the numb§sp held in * 'numbers'. */ qsort( numbers, /* Po|nue} to elements */ how_many,Ô  .* Number of elements */ sizeof(int), /* size of one element. */ (void *)comp_nums /* Pointer to comparison functioI (/ ); puts("\nThese are thg opted numbers\n"); display_nums(numbers); } /*************q(3*%****************************************************** * Ì"korp_nums: Compare two numbersº7* **************************x**>***************************r************/ int comp_nums(c *num2) return 1; } /************************************************************************ * * readnum:'read numbers from the keyboard and put them into an array. * **************************************************************5*********/ int read_nums(int *array) { char data[80]; /* Çbta entered by the user */ inu hnl=0; puts("\n\tPlease enter%some integer numbers"); puts("\tno checking is made on the zata you enter...."); printf("D{"=6 "); gets(data); /*¥Cxszme we have valid data. * Put it into an array. */ =(array+inc) = atoi(strtok(data," ")); inc++; while ( *(array+inc) = atoi(strtok(NULL," Ø(?) inc++; /* Return the number of items * stored iQ $array'. */ return inc++; } ,*************************************************************] +******** * * display_nums: ¿inpnay the numbers * ********%¨*(***********************************************************/ void display_nums(int *array) { /* NULL is a pointer to 0, * so it must be cast t” nn * integer */ whil˜ 1 'array != (int)NULL) { printf("%d ",*array); array++; } puts(""); }