--------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F4B00044 Date: 04/05/98 From: BILL BIRRELL Time: 07:19am \/To: ``TICAL`` (Read 1 times) Subj: [03/4] CritErr handler You have completely missed the point (or pointers), Paul. :-) > This is a C++ question, but this is the closest > forum we have here to post this on. Nope. Your code is C, but there *is* a CPLUSPLUS echo. > I was reading in a C++ book that inside of > structures, you can define data > types of that structure... Like so: > struct list > { char monkey; > list *list; > list *invertebrate; > int beligerant; int aggressive; ('belligerent' really means 'waging war'). > } BTW when I was an infant visiting the zoo, I used to wonder what a 'dangerou' was. After all the sign said 'These animals are dangerous'. :-) The point is that a structure can contain POINTERS to another structure of the same type, but obviously not the structures themselves. This allows the structure to become self-referencing without becoming self-perpetuating. :-) Where it might be useful would be in a node in a tree stucture. Examples of how to do this in C are given in K&R, and the theory of tree structures is discussed in Knuth ad infinitem/nauseam, whichever comes first. Best wishes, Bill. ... porcupines do it very carefully. --- * Origin: bill@escan.demon.co.uk (2:2504/200) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F4B00045 Date: 04/05/98 From: BILL BIRRELL Time: 07:24am \/To: ROGER SCUDDER (Read 1 times) Subj: Ancient history Hi Roger, > 30 Mar 98 21:41, John Gardeniers wrote to David Noon: > JG> I have a very simple rule, which has served me well for decades. > Sorry for going off a bit here, but I didn't know > that you had > been at this for that long. That kind of makes me > feel like a > real newcomer with having only started any kind of > programming > toward the end of 94'. John's good, but even he can't have been doing it in C for more than two decades. :-) Bell Labs didn't produce C until 1978. :-) Tell me, Roger, what have sorting algorithms to do with C? :-) .... you didn't start it, I hasten to add. :-) Best wishes, Bill. ... Marines do it at sea. --- * Origin: bill@escan.demon.co.uk (2:2504/200) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F4B00046 Date: 04/05/98 From: BILL BIRRELL Time: 07:34am \/To: HERMAN SCHONFELD (Read 1 times) Subj: cprintf Herman, >> Now I can truely say that most compilers have cprintf().. Fair deal? > BS> Fair enough. > Which compilers don't have the elementary console > printf? You appear to have misunderstood. There are functions which are part of a standard library, and there are functions which are extensions to the standard libraries. An example of the first sort is 'int printf(char *format [,argument] ...);', while an example of the second sort would be 'int cprintf(char *format [,argument] ...);'. They are different functions. All standard compilers must have all of the first sort. No standard compiler is required to have any of the second sort. Therefore you *cannot rely* on any of the functions of the second sort ever being there, and if they are there, you cannot expect that all manufacturers will have implemented such discretionary functions in the same way or even to perform the same tasks. Best wishes, Bill. ... Postmasters are not required to give or authorised to demand change. --- * Origin: bill@escan.demon.co.uk (2:2504/200) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F4B00047 Date: 04/05/98 From: BILL BIRRELL Time: 07:41am \/To: SIMON AVERY (Read 1 times) Subj: Stuff Hey Simon, > I'd say about 90% of my coding is for Fido-related > projects! Nice to hear from you again. :-) > Got it to clean compile last night, haven't had time > to test the thing yet. (Best backup first...) Speaking of that ... example code follows ... somebody asked for it ... forget who ... all Microsoft bits laboriously removed, and nothing left but bog standard ANSI ... > BB> Anything anybody wants or wants to know, just ask. :-) I don't > BB> bite ... ... ... often. :-) > Goes for me too. ----------------------------------------------------- /* compile with structures packed on 1 byte */ /* MSGHDR.H */ struct msgtoidx { unsigned char length; char message[35]; }; struct msgstr { unsigned char length; char text[72]; }; struct msghdr { int msgnum; unsigned prevreply,nextreply,timesread,startblock,numblocks, destnet,destnode,orignet,orignode; unsigned char destzone, origzone; unsigned cost; unsigned char msgattr,netattr,Board; char time[6],date[9]; struct msgtoidx whofrom, whoto; struct msgstr subject; }; ------------------------------------------------------------ /* MSGHDR.C. A sample program to illustrate one method of accessing the Hudson Messagebase of a FidoNet mailer or BBS. Generic C ... not generic BBS. Compile with packed structures on 1 byte to be compatible with the Pascal code that first wrote them to disk. All pretty simple. */ #include #include /* for exit() */ #include "msghdr.h" /* see above */ #include /* for strings */ #include /* for LONG_MAX */ #include /* for isprint()*/ int DEBUG; /***************************************/ /* hardwired - must sort this out */ /* data is available from RA or FD */ /* each has its own configuration file */ /* either SETUP.FD or Config.RA */ /***************************************/ char *hdrfile="F:\\BBS\\MSGBASE\\MSGHDR.BBS"; char *txtfile="F:\\BBS\\MSGBASE\\MSGTXT.BBS"; void bugout(FILE* fd, char *p) { printf("Error: can't find %s\n",p); fclose(fd); exit(-1); } int main(void) { FILE *fp; struct msghdr m; long rec, flen; int j, k, n, o, nrecs; char c, blurb[256]; struct block { char length; char text[255]; } buffer; if((fp=fopen(hdrfile,"r")) == NULL) bugout(fp,hdrfile); fseek(fp,0l,SEEK_END); flen=ftell(fp); /* get file length in generic way */ fseek(fp,0l,SEEK_SET); if(DEBUG) printf("\n\tFile length is %ld",flen); nrecs = (int)(flen/(long)sizeof(m)); printf("\n\tNumber of records is: %d\n",nrecs); rec = LONG_MAX; /* limits.h */ do { printf("\r\tenter a record number\n\t"); scanf("%ld",&rec); } while (rec > nrecs); fseek(fp,(rec-1)*(long)sizeof(m),0); fread((char *)&m,sizeof(m),1,fp); fclose(fp); printf("\n\tBoard %d",m.Board); if(m.prevreply != 0) printf("\n%d\t",m.prevreply); else printf("\n\t"); printf("Message Number %d",m.msgnum); if(m.nextreply!=0) printf("\t%d\n",m.nextreply); else printf("\n"); printf("\n\tOriginator: %d:%d/%d.0",m.origzone,m.orignet,m.orignode); printf("\n\tAddressee: %d:%d/%d.0",m.destzone,m.destnet,m.destnode); printf("\n\tTo: %s",m.whoto.message); printf("\n\tFrom: %s",m.whofrom.message); /* now deal with Pascal type string */ strncpy(blurb,m.subject.text,m.subject.length); blurb[m.subject.length] = '\0'; printf("\n\tSubject: %s\n",blurb); /* go get text from msgtxt now */ if((fp=fopen(txtfile,"r"))==NULL) bugout(fp,txtfile); if(DEBUG) printf("\n\tStarts %d, for %d blocks\n",m.startblock,m.numblocks); j = (int) m.numblocks; fseek(fp,(((long)m.startblock) * ((long)sizeof(buffer))),SEEK_SET); if(DEBUG) printf("\nOffset is %ld",ftell(fp)); for (n = 0; n < j; n++) { fread((char *)&buffer,sizeof(buffer),1,fp); k = (int) buffer.length & 255; for (o = 0; o < k; o++) { c=(char)buffer.text[o]; if(isprint(c)) putchar(c); else if(c==13) putchar('\n'); else if(c == 1) putchar('@'); } } fclose(fp); return 0; } -------------------------------------------------- Hakuna matata, Bill. ... Meerkats do it in the desert. --- * Origin: bill@escan.demon.co.uk (2:2504/200) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F4B00048 Date: 04/05/98 From: BILL BIRRELL Time: 10:39pm \/To: SIMON AVERY (Read 1 times) Subj: Bug Hi Simon, Ref my last. Because the msgbase files also contain binary information, they should both be opened in the "rb" mode, not plain "r". Sorry! The bug crept in because I changed it to fread() from _read() to kill the extensions to ANSI. :-( It was the obvious bug - fread() stopped prematurely on receiving an 0x1a, but it took a bit of head scratching to track it down. If you've kept a copy please modify it. Hakuna matata, Bill. --- * Origin: Meerkats Anonymous (2:2504/200) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F4B00049 Date: 04/05/98 From: DAVID NOON Time: 06:39pm \/To: HERMAN SCHONFELD (Read 1 times) Subj: Exchanging A Radix In a message dated 04-03-98, Herman Schonfeld said to David Noon about Exchanging A Radix Hi Herman, HS>Thanks for the free lessons, if I need any more, I'll ask. You are welcome. ... :-) HS>Some of your comments are untrue. Really? Which ones? HS>I agree that a radix sort HS>would prove obsolete with memory-constrained enviroments, HS>however, it most definalty is an effective method (fast at HS>that) of sorting numbers of a wide range. How about floating point? ... ;-) HS>Such applications as z-depth sorting are possible due to this. Three-dimensional geometry. We all do that sort of stuff all the time, don't we? HS>As latterly HS>commented, radix sort is not for small arrays and minimal HS>distribution. It's also pretty useless for sorting structs, HS>but it is the fastest method I know of for depth sorting HS>polygons, and if you can prove to me otherwise, good luck. Since you say "it is the fastest method I know", I would be mightily challenged to prove the truth or falsehood of that statement, as I don't know the extent of your knowledge. I think this thread has also reached its sensible point of termination, so you may treat my questions above as rhetorical. [Which is what they are, anyway.] Regards Dave ___ * MR/2 2.25 #353 * Indonesia fully supports the Australian Anti Gun Lobby. --- Maximus/2 3.01 * Origin: DoNoR/2,Woking UK (44-1483-717905) (2:440/4) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F4B00050 Date: 04/05/98 From: DAVID NOON Time: 06:51pm \/To: HERMAN SCHONFELD (Read 1 times) Subj: Bubble And Squeak Sortin In a message dated 04-03-98, Herman Schonfeld said to David Noon about Bubble And Squeak Sorting Hi Herman, DN> worst case: O(n**2/2) comparisons, O(n**2/4) exchanges HS>What are the two multiplication symbols supposed to HS>represent? I apologize as I am not familiar with your elite HS>talk. That's the notation for exponentiation in programming languages that support that operation (e.g. FORTRAN, PL/I, some implementations of ALGOL 60 & 68). So, n**2 = "n squared". HS>Last time I checked, to compare two or more functions HS>you go HS>a) function "a" ran for <..> and took <..> time HS> function "b" ran for <..> and took <..> time We aren't immediately comparing functions, but algorithms. For function benchmarking, try a similar thread in the C_PlusPlus echo; it's just getting started. Algorithmic comparisons of things such as sorting are done with combinatorial analysis, with notional overheads assigned to specific operations (comparison, copy, exchange, etc.) and the combinations of overheads summed to give an idea of the algorithm's performance on a dataset of size n. The big-o and little-o notations describe how firmly the bound can be applied. Take a decent university course in numerical analysis for this. It is major topic drift in a C programming echo. HS>b) Or a simple table of what (and how) you did and tested it usually HS>helps HS> pick out the flaws in your test (if any). HS>c) You post your program for others to test. I have already done so. Again, check out the C_PlusPlus echo. Since we have drifted a long way from coding, I suggest we terminate this thread here. Regards Dave ___ * MR/2 2.25 #353 * Purchasing Windows is an Unrecoverable Application Error. --- Maximus/2 3.01 * Origin: DoNoR/2,Woking UK (44-1483-717905) (2:440/4)