| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | qsort |
Hi Bob,
On Dec 12 07:58, 1996, Bob Lawrence of 3:711/934.12 wrote:
BL> I've finally got around to looking at your C qsort() code and it
BL> works!
Yay!
BL> I had to correct a few errors before it would compile...
Fair enough - my ability to write portable code has improved over
the last 3 or 4 years.
BL> /*
BL> * L I N E S O R T 0
BL> *
BL> * Sort a char array full of nul-terminated strings
BL> *
BL> * Written by M. Stapleton of Graphic Bits
BL> *
BL> * Modified from a Snipet by Bob Lennon
BL> *
BL> * Sep 11 1993
BL> */
BL> #include
BL> #include
BL> #include
BL> #include
BL> #include
BL> /* Compare Sort Elements */
BL> int pscompare(const void *a, const void *b)
BL> ... ^^^^ it didn't like this missing
BL> {
BL> return strcmp(*(char **)a, *(char **)b);
BL> }
BL> #define MAXS 120
BL> #define MAXP MAXS
BL> #define MAXR 26L
BL> /*#define RAND_MAX SHRT_MAX */
BL> ... for some reason it didn't like RAND_MAX defined as SHRT_MAX
BL> ... so I just used SHRT_MAX. You programmers are strange...
Sorry about that - my dumb compiler doesn't have a RAND_MAX. I
should've used #ifndef RAND_MAX.
BL> char strs[MAXS]; /* The null-separated strings */
BL> char *strptrs[MAXP]; /* String pointer table */
BL> #define wrand() (rand() & SHRT_MAX)
BL> ... ^^^^^^^ it didn't like wrand(z) and rand(z) and I can
BL> ... understand that. I don't like it either.
This was an attempt at a portable rand() that returns a short int
because my rand() returns a 32 bit int.
I don't understand why it complained about the z, though, since
wrand() is not "called" with an argument.
BL> int main(void)
BL> {
BL> unsigned maxpi, pi, si;
BL> char ch=0, **dpch;
BL> /* Fill the string table with random-length alpha strings */
BL> for (si=0; si * Origin: Graphic Bits (3:711/934.33)SEEN-BY: 711/934 712/610 @PATH: 711/934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.