--------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F4G00031 Date: 04/12/98 From: KURT KUZBA Time: 01:40am \/To: JOHN HAMLIN (Read 1 times) Subj: Running clock JH> PH> Another way would be to check the time (using JH> PH> standard C time functions or system BIOS functions or JH> PH> reading I/O ports directly) within your program's JH> PH> main loop, and update the clock's display whenever JH> PH> the time changes. JH> The prob with this method, is that if there is a "wait JH> for keypress" in the loop, then the clock stops untill JH> the next keypress. You have to take that into account and construct your getkey function accordingly. In this example, you can pass a filter string, or NULL, and whether to wait or return immediately if no key has been pressed. The update_clock() routine should be separate so it may be called from various places, or not called if the display is one where it is not wanted. One could also make the call to update_clock() dependent upon a variable as well. int getkey_clock(char *filter, int wait) { int result = 0; do { if(kbhit()) { result = (0 == (result = getch())) ? -getch() : result; if(filter && !strchr(filter, result)) result = 0; } update_clock(); } while(!result && wait) return result; } > ] Conspiracy? There's no conspiracy. Go ahead. Ask anyone..... --- * Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F4G00032 Date: 04/12/98 From: KURT KUZBA Time: 01:40am \/To: CAREY BLOODWORTH (Read 1 times) Subj: BUBBLE AND SQUEAK SORTIN CB> (I should also point out that with most real 'bubble sorts', CB> there will only be 'n' exchanges. Most implementations will CB> find the highest/lowest and then exchange in the outer loop, CB> rather than in the inner on every successful comparisons. CB> [Well, the 'highest' will be set, but that's very different CB> from exchanging, esp. when the data is large structures.]) What... No example!? Now you have only one swap for each element which is out of place. This is not really a bubble sort, though, since the elements don't actually migrate toward their place, but just jump there all at once. I guess it would have to be a sort of a hyper-bubble sort. /* bubble.c PUBLIC DOMAIN */ #include #include void bubblesort(int *array, int elements) { int outer, inner, swap, tmp, end, reverse; reverse = (elements < 0) ? 1 : 0; elements = reverse ? -elements : elements; end = elements - 1; /* We do this so that we need not shake our fists toward Borland International in our rage. :) */ for(outer = 0; outer < end; outer++) { swap = outer; for(inner = outer; inner < elements; inner++) if((array[swap] > array[inner] && !reverse) || (array[swap] < array[inner] && reverse)) swap = inner; if(swap > outer) { tmp = array[outer]; array[outer] = array[swap]; array[swap] = tmp; } } } void show_array(int *array, int max) { int i; for (i = 0; i < max; i++) printf("%4d", array[i]); } int main(void) { int table[10] = { 70, 21, 49, 7, 63, 42, 14, 56, 35, 28 }; puts("\n\n\tThis program demostrates sorting array " "elements into\n\tascending/descending order" " using a simple bubble sort."); printf("\n\n Unsorted array is ::"); show_array(table, 10); bubblesort(table, 10); printf("\n\n Ascending sort array ::"); show_array(table, 10); bubblesort(table, -10); printf("\n\n Descending sort array ::"); show_array(table, 10); puts("\n"); getch(); return 0; } > ] You want me to stay current? I can barely stay awake!!...... --- * Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F4G00033 Date: 04/12/98 From: KURT KUZBA Time: 01:40am \/To: BILL BIRRELL (Read 1 times) Subj: compact efficient code BB> For Ms-Dos I just include "device=ansi.sys" in config.sys BB> and Bob's your uncle. Works like magic every time. Pretty BB> colours, cursor control, windows, the lot! Try that first. The Borland cprintf() is entirely independent of system IO. The output does not get filtered through ANSI.SYS because it does not use stdout, so you have to make your own emulator to handle it. Borland's conio output functions use direct video memory access, necessitating the use of internal emulation, using gotoxy(), textattr(), and putch(). > ] I am Borgs Bunny. What's assimilated, Doc?.................. --- * Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F4G00034 Date: 04/12/98 From: KURT KUZBA Time: 01:40am \/To: RUSS WUERTZ (Read 1 times) Subj: Ansi.Sys RW> Your opinion is that getStream(1) as defined in stdio.h RW> cannot be used to capture those ANSI escape sequences so RW> that I can print out with cprintf. I have cprintf here RW> in its C function form so that I could change it around RW> (re-compile it and put it back into my lib). cprintf() and stdout have nothing to do with eachother, usually. __getStream(1) assigns a file pointer to stdout. The Borland default implementation of cprintf() is a direct video memory access data manipulation. I believe, however, that you may specify that it be otherwise. I will check... [ dig .. dig .. shuffle .. rumble .. RUMBLE?! Landslide! ] ( scrambling out, standing up, brushing self off ) Ah... found it. Try putting directvideo = 0; in your code. That may be what you are seeking. Otherwise, if it is your intention to limit the output window on the stdout display, then that IS possible, though I don't know the means whereby it is done. There were examples of this posted in the past, but I don't seem to have any of them in my personal archives. It would not conform to your window() parameters unless you specifically informed it of those parameters, however. Changing the value of directvideo to 0 may cause an automatic interpretation of data to keep it all in a defined area, or maybe they even tweek the output parameters via some interrupt call for you. Hmm... I should just test it, shouldn't I? [ fumble .. fumble .. mix .. mix .. shake .. shake .. AhaH! ] Ok. It didn't work. This is what I tried. It didn't intercept the escape sequences at all. Perhaps I should have opened it in binary, but I don't think it would make much difference, as far as interpretation of escape sequences is concerned. I think intercepting and interpreting the color and cursor changes before sending the output to cprintf() is the way. #include #include int main(int argc, char **argv) { FILE *Read_in; char buf[512]; if(argc < 2) { puts("usage: wndotest filename.ext"); return 1; } Read_in = fopen(argv[1], "r"); if(!Read_in) { printf("Unable to open %s.\n", argv[1]); return 2; } window(1, 1, 80, 25); directvideo = 0; clrscr(); while(fgets(buf, 512, Read_in)); cprintf(buf); fclose(Read_in); getch(); return 0; } > ] Optimist: Says I'm not all bad when I'm not much good....... --- * Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F4I00000 Date: 04/14/98 From: HERMAN SCHONFELD Time: 07:37am \/To: DAVID NOON (Read 2 times) Subj: Faster Than A Snail On . > If the Shellsort in SNIPPETS is the one posted by Bill Birrell and BS>Herman > Schonfeld then it is a sub-optimal parameterisation (i.e. crepe). Use BS>an > instantiation of the one I posted in C_PlusPlus instead. What's so crap about my shellsort? -- Mine -- void SHELL() { int gap; int i; int j; int temp; for(gap = lastone / 2; gap > 0; gap /= 2) for(i = gap; i < lastone; i++) for(j = i - gap; j >= 0 && data[j] > data[j + gap]; j -= gap) { temp = data[j]; data[j] = data[j + gap]; data[j + gap] = temp; } } -- Snippets -- BS>void ssort (void *base, BS> size_t nel, BS> size_t width, BS> int (*comp)(const void *, const void *)) BS>{ BS> size_t wnel, gap, wgap, i, j, k; BS> char *a, *b, tmp; BS> wnel = width * nel; BS> for (gap = 0; ++gap < nel;) BS> gap *= 3; BS> while ( gap /= 3 ) BS> { BS> wgap = width * gap; BS> for (i = wgap; i < wnel; i += width) BS> { BS> for (j = i - wgap; ;j -= wgap) BS> { BS> a = j + (char *)base; BS> b = a + wgap; BS> if ( (*comp)(a, b) <= 0 ) BS> break; BS> k = width; BS> do BS> { BS> tmp = *a; BS> *a++ = *b; BS> *b++ = tmp; BS> } while ( --k ); BS> if (j < wgap) BS> break; BS> } BS> } BS> } BS>} Now _THAT_ wins first prize for crappy code -- Not only is it slower, it's also alot more cumbersome. In future, please try to make your comments as accurate as possible as I tire of constantly seeing remarks by you which are, as per usual a) drastically inaccurate b) ignorant speak c) flame bait ... DOSSHELL? Of course DOS is hell. --- Ezycom V1.48g0 01fd016b * Origin: Fox's Lair BBS Bris Aus +61-7-38033908 V34+ Node 2 (3:640/238) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F4K00000 Date: 04/15/98 From: BOB STOUT Time: 11:13am \/To: JASEN BETTS (Read 2 times) Subj: LICORICE ALLSORTS On , Jasen Betts (3:640/350@fidonet) wrote: > ... and the winner is rg_qsort by a small fraction over the library > function. > Bubblesort, isertion etc: Don't do this at home -ah- work :) My uickerSort > is beginning to look sick too. SHELLsort may be faster with a more > efficient swap routine. > F-Bubble and insertion are the fastest on sorted lists, but that's about > all they have going for them. > Well, I learned that even with tiny arrays Qsort has a speed advantage, nd > with it provided as a library function, and in snippets there's not much > excuse for not using it. Jasen... I also feel compelled to point out that Ray Gardner also has both insertion and shell sorts in SNIPPETS. ;-) I also have at least two versions of heap sorts, one of which will be included in the next SNIPPETS release. --- QM v1.00 * Origin: MicroFirm : Down to the C in chips (1:106/2000.6) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F4K00001 Date: 04/15/98 From: BOB STOUT Time: 11:22am \/To: JOHN GARDENIERS (Read 2 times) Subj: WHERE.C [2 of 3] John... Only parts 1 & 2 made it here. --- QM v1.00 * Origin: MicroFirm : Down to the C in chips (1:106/2000.6) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F4K00002 Date: 04/15/98 From: BOB STOUT Time: 11:22am \/To: ALEXIS TCACH (Read 2 times) Subj: Read keyboard On , Alexis Tcach (4:900/470.8@fidonet) wrote: > Does somebody know how to read 2 (or more) keys from the keyboard at the > same time ??? This is highly machine- and OS-specific. What are you using? --- QM v1.00 * Origin: MicroFirm : Down to the C in chips (1:106/2000.6) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F4K00003 Date: 04/15/98 From: BOB STOUT Time: 11:25am \/To: JASEN BETTS (Read 2 times) Subj: LICORICE ALLSORTS Jasen... The Subj: line interests me. There was another Ozzie who used to post here who reinvented some sort (pun intended) of sorting algorithm which he called "Licorice" something-or-other. Ring any bells? --- QM v1.00 * Origin: MicroFirm : Down to the C in chips (1:106/2000.6) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F4L00001 Date: 04/16/98 From: CAREY BLOODWORTH Time: 09:51pm \/To: RICHARD VETO (Read 2 times) Subj: Help with overlays RV>did notice that within the project hierarchy, there is an option to overlay RV>node.If I click it and compile, I notice that overlay.lib is included, yet n RV>overlay file is created. My target is dos exe under 16 bit. The overlayed code is usually bundled right along in with the executable. It's not like it was 10 years ago when the overlays were seperate .ovr files. Nowdays, it's usually (always?) all bundled into a single executable and the overlay manager knows to go to the executable at a specific point and load in a particular module. --- QScan/PCB v1.19b / 01-0162 * Origin: Jackalope Junction 501-785-5381 Ft Smith AR (1:3822/1)