TIP: Click on subject to list as thread! ANSI
echo: locsysop
to: Bob Lawrence
from: Michael Stapleton
date: 1996-12-02 21:29:38
subject: posix

Hello Bob,

On Jan 01 07:50, 1996, Bob Lawrence of 3:711/934.12 wrote:

BL> (grin).  The absoultely worst part of C is the way they bend the
BL> rules with pointers.  After coming back from Pascal, I finally
BL> understand that it is not the concept of pointers that is
BL> horrific in C, it's their fuckwit conventions.  I still can't
BL> believe *(void **)a!

What's weird about C pointers ?  Apart from the scaling, they are
just like flat assembler pointers. I think you're having problems
with C because you are thinking in Pascal.

BL> I've been trying to use the qsort() function to sort a pointer
BL> array of strings, and I defy *anyone* to do that successfully.
BL> It even gets a mention in the Borland help!  file (not that it
BL> helps in the least).

/*
 *  L I N E S O R T 0
 *
 *  Sort a char array full of nul-terminated strings
 *
 *  Written by M. Stapleton of Graphic Bits
 *
 *  Modified from a Snipet by Bob Lennon
 *
 *  Sep 11 1993
 */

#include 
#include 
#include 
#include 
#include 

/* Compare Sort Elements */
int pscompare(void *a, void *b)
{
     return strcmp(*(char **)a,  *(char **)b);
}

#define MAXS 120
#define MAXP MAXS
#define RAND_MAX SHRT_MAX
#define MAXR 26L

char strs[MAXS];        /* The null-separated strings */
char *strptrs[MAXP];    /* String pointer table */

#define wrand(z) (rand(z) & SHRT_MAX)

int main(void)
{
    unsigned maxpi, pi, si;
    char ch=0, **dpch;

    /* Fill the string table with random-length alpha strings */
    for (si=0; si 9L*RAND_MAX)
            ch = '\0';
        else
            ch = 'a' + MAXR * wrand() / RAND_MAX;

        strs[si] = ch;
    }
    strs[MAXS-1] = '\0';    /* Null terminate the table */

    /* Build string pointer table */
    strptrs[0] = strs;
    for (pi=1, 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™.