/*Translated by FOR_C, v3.4.2 (-), on 07/09/115 at 08:33:08 */ /*FOR_C Options SET: ftn=u io=c no=p op=aimnv pf=,p_csort s=dbov str=l x=f - prototypes */ #include #include "fcrt.h" #include #include #include "p_csort.h" /*>> 1996-05-31 DRCSORT Krogh Added comments for conversion to C. *>> 1988-11-22 DRCSORT Snyder Initial code. * * Test driver for CSORT. * * Construct an array of 1000 random strings of length 10. * Sort it on the 2:9 substring using CSORTP. * Check whether it is in order. * Sort it on the 2:9 substring using CSORT. * Check whether it is in order. * */ #include int main( ) { char c[1000-(1)+1][11]; LOGICAL32 ok; long int i, j, k, p[1000-(1)+1]; static char lettrs[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; /*++ CODE for ~.C. is inactive * character CTEMP*10 *++ END */ /* Generate 1000 random strings of length 10 */ for (i = 1; i <= 1000; i++) { for (j = 1; j <= 10; j++) { k = 25*sranu() + 1; c[i-(1)][j - 1] = lettrs[k - 1]; } } /* Sort them using CSORTP. */ ok = TRUE; csortp( (char*)c,11, 1, 1000, 2, 9, p ); /* Check the order. */ for (i = 2; i <= 1000; i++) { ok = ok && lge( ntstr(c[p[i-(1)]-(1)]+1,8), ntstr(c[p[i - 1-(1)]-(1)]+1,8) ); } /* Print the results. */ if (ok) { printf("CSORTP succeeded\n"); } else { printf("CSORTP failed\n"); } /* Sort them using CSORT. */ ok = TRUE; /*++ CODE for ~.C. is inactive * call csort (c,1,1000,2,9,ctemp) *++ CODE for .C. is active */ csort( (char*)c,11, 1, 1000, 2, 9 ); /*++ END * Check the order. */ for (i = 2; i <= 1000; i++) { ok = ok && lge( ntstr(c[i-(1)]+1,8), ntstr(c[i - 1-(1)]+1,8) ); } /* Print the results. */ if (ok) { printf("CSORT succeeded\n"); } else { printf("CSORT failed\n"); } exit(0); } /* end of function */