/*>> 2001-04-02 Krogh Minor change in header files, ctemp deleted */ /*>> 1993-03-31 CLL csort1() is unique code for C. No MATH77 equivalent. */ /*>> 1993-02-10 CLL */ #include "fcrt.h" /* TRUE */ #include #include /* strncmp() */ #include /* malloc() */ #include "p_csort1.h" /*>> 1988-11-22 DRCSORT Snyder Initial code. * * Test driver for CSORT1/ * * Construct an array of NCHAR random strings of length 10. * Sort it on the 2:9 substring using CSORT1. * Check whether it is in order. * */ #define NCHAR 101 int main( ) { char *c[NCHAR]; LOGICAL32 ok; long int i, j, k ; static char lettrs[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char alpha; /* Generate NCHAR random strings of length 10 */ for (i = 1; i <= NCHAR; i++) { c[i-1] = malloc(11); for (j = 1; j <= 10; j++) { k = 25*sranu(); alpha = lettrs[k]; *( c[i-1]+(j - 1)) = alpha; } *(c[i-1]+10) = '\0'; } /* Sort them using CSORT1. */ ok = TRUE; csort1( c, 1, NCHAR, 2, 9); /* Check the order. */ for (i = 2; i <= NCHAR; i++) { ok = ok && (strncmp(c[i-1]+1, c[i-2]+1, 8) > 0); } /* Print the results. */ if (ok) printf( "CSORT1 succeeded\n" ); else printf( "CSORT1 failed\n" ); exit(0); } /* end of function */