--------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: F1K00007 Date: 01/15/98 From: BRIAN WOOD Time: 11:33am \/To: VICTOR KEMP (Read 1 times) Subj: converting char to string VK> Hi, how do you convert a char to a string? I'm not sure you can, because there could be no '\0' to end the string. VK> I would like to concatenate a single char onto the end of a string but VK> it says it can't convert int to char * when I do this: VK> char charvar; VK> char stringvar[90]; VK> strcat(stringvar, charvar); That makes sense, strcat() requires a char *, and a char gets promoted to int so the compiler can't match it up with strcat(char *, const char*) VK> I also tried doing: VK> strcat(stringvar, (char *)charvar); VK> but that made a big mess of things although gave no error message. That makes sense too, because strcat would copy everything from (char *)charvar (an address), until a '\0' were found at a higher address, right? so you would end up with stringvar being filled with your char, plus a bunch of garbage, or overwriting it with too many characters and probably crashing the app altogether. Maybe this would work, but there are probaly several right answers. int t=strlen(stringvar); if(t TOPIC: 203 C++ Ref: F1K00008 Date: 01/14/98 From: DAVID NOON Time: 08:28pm \/To: MICHAEL RATHBURN (Read 1 times) Subj: Sort Algorithm In a message dated 01-12-98, Michael Rathburn said to All about Sort Algorithm Hi Michael, MR>Can someone explain how this sort works I have tried to follow it but I MR>just get confused. [snip] MR>this is the confusing part :- MR> while(test == 0) MR> { MR> test = 1; MR> for (i = 0; i < (MAX - 1); i++) MR> { MR> if (table[i] < table[i + 1]) MR> { MR> temp = table[i]; MR> table[i] = table[ i + 1]; MR> table[i + 1] = temp; MR> test = 0; MR> } MR> } MR> } The simplest response is that it sorts very, very s-l-o-w-ly. This is a bubble sort. The while(test == 0) loop keeps the sort looping until the flag variable 'test' fails to keep its change to 1 that immediately follows. This failure happens whenever an exchange occurs inside the if() statement, inside the for() loop. Thus, the loop keeps looping until no more exchanges have been made. Since the criterion for an exchange is that 2 adjacent elements are out of sorted sequence, no exchanges means that everything is in sorted sequence. Then the loop exits, as the array is sorted. Note that bubble sort is offered by Knuth, and several others, as by far the worst sorting algorithm around. The next step up is insertion sort, which typically runs twice as fast. The "great all-rounder" is Shell's algorithm. The "formula 1 racer" is Hoare's algorithm (usually very fast, but is prone to breaking down). The "status symbol" of sorting is Batcher's algorithm. However, C++ programmers are usually renowned for their ignorance of sorting algorithms, so this thread could be too enlightening to be on-topic in this echo. I suggest we move it to Pgmrs, where algorithms in general are on-topic. Regards Dave ___ * MR/2 2.25 #353 * They'll release Windows 97 when NT 4.0 finishes loading. --- Maximus/2 3.01 * Origin: DoNoR/2,Woking UK (44-1483-717905) (2:440/4) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: F1K00009 Date: 01/13/98 From: LEE BRAIDEN Time: 07:19am \/To: VICTOR KEMP (Read 1 times) Subj: RE:DJGPP Hi Victor, VK> I have jsut installed DJGPP congratulations on choosing the right compiler (for DOS anyway..) ;=) VK> and I it is giving me an error, I don't want to spend much time digging VK> through all the docs, I just need to compile something. Hmm.. better read 'em anyway - you won't get too far without them. DJGPP is a great system, but great systems are rarely simple. VK> This is what gcc says when I run it: VK> gcc.exe: installation problem, cannot exec `as': No such file or VK> directory (ENOENT) VK> I can't find any files called 'as.exe' or anything, is it meant to be VK> there or is it trying to execute a typo error or something? VK> If you unpacked everything properly, you should have it in the bin directory, same place as gcc, make, etc. If it's not there, you need to get the rest of the files (either as*.zip or binutils*.zip - can't remember now). If you've got it there, then you just need to set up your environment by running the .BAT file which is also in the bin directory. Best bet is to CALL it from autoexec.bat. If I remember correctly, you need to SET DJGPP="" where is the directory containing the bin directory - probably SET DJGPP="c:\djgpp". Read the docs - it's all in there. P.S.: If you want to do games/graphics, get your hands on the Allegro library - it should be available wherever you got DJGPP. Later, - Lee --- Lee Braiden FIDO: 2:443/777.3 EMail: lee.braiden@coole.piglets.com --- FIPS/32 v0.98 W95/NT [Unreg] * Origin: Oppression is nine tenths of the law (2:443/777.3) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: F1K00010 Date: 01/14/98 From: MICHAEL RATHBURN Time: 09:57am \/To: ALL (Read 1 times) Subj: WinExec() Hi All , hope you are having a nice day Can some explain why my BCBuilder compiler says the argument SW_SHOWMAXIMIZE is undefined in a Call to winexec(); I have called it Like WinExec("pbrush.exe" ,SW_SHOWMAXIMIZE); Am I using the right function ? I am trying to make a menu that executes windows programs when you click on a button and control the state of the window ie: minimised maximised or normal. I have consulted the help file which reveals Zilch. searched the online manuals on my Borland C++ CD another Zilch :-( I have included stdlib.h but i'm not sure if it needs it. -=> Yours sincerely, Michael Rathburn <=- ... AARRGGHH. I'll kill myself. I quoted 6%! ~~~ Tag-O-Matic V.13 ! I recognise the Green Frog. --- Terminate 5.00/Pro * Origin: Terminate has most advertising origin lines ;-) (2:250/124.19) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: F1K00011 Date: 01/14/98 From: MICHAEL RATHBURN Time: 02:01pm \/To: ALL (Read 1 times) Subj: winexec() Hi All , hope you are having a nice day re:- WinExec("pbrush",SW_SHOWMAXIMIZE); Ive managed to sort out what was going wrong I was using SW_SHOWMAXIMIZE instead of SW_MAXIMIZE Is there any way I can pass WinExec a file pointer so that pbrush executes with a specific file loaded ? -=> Yours sincerely, Michael Rathburn <=- ... "I am Popeye of Borg. Prepare to be askimiligrated." ~~~ Tag-O-Matic V.13 ! (39 Taglines) (Quoted 13%) Owned by Michael Rathburn --- Terminate 5.00/Pro * Origin: Terminate point system, the easiest in the world! (2:250/124.19) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: F1K00012 Date: 01/14/98 From: ALEXEY MOKHOV Time: 07:56pm \/To: ADAM MAJER (Read 1 times) Subj: screen blinking - the problem is solved Hello, Adam! Your advice to try with fewer buttons was decisive. Thanks a lot. The bug was found into the dialog constructor: The last operator of the constructor was the call of some function. This function calls another one, wich calls anosher one, ... wich calls Invalidate for every button. But dialog constructor is not finished at this moment! No parent-child ralationship for dialog window interface elements are set! Really childs mistake ... Now I know much better what for we need SetupWindow function. After replacing the function call from constructor to SetupWindow the desktop window is in peace and dialog window with buttons appears 10 times faster. Alexey --- GoldED 3.00.Alpha4+ * Origin: St_1, St.Petersburg Russia (2:5030/155.19) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: F1K00013 Date: 01/16/98 From: KURT KUZBA Time: 01:05am \/To: MICHAEL RATHBURN (Read 1 times) Subj: sort algorithm MR> //sort MR> int temp, test = 0; MR> // this is the confusing part :- MR> while(test == 0) MR> { MR> test = 1; MR> for (i = 0; i < (MAX - 1); i++) MR> { MR> if (table[i] < table[i + 1]) MR> { MR> temp = table[i]; MR> table[i] = table[ i + 1]; MR> table[i + 1] = temp; MR> test = 0; MR> } MR> } MR> } It's pretty simple, really... int temp, test = 0; // define a test condition while(test == 0) // while a test condition exists { test = 1; // clear the test condition for (i = 0; i < (MAX - 1); i++) { // for each element in the array if (table[i] < table[i + 1]) { // if the present element is less than // the next element temp = table[i]; // save the value of this element table[i] = table[ i + 1]; // move the next element to this slot table[i + 1] = temp; // make present element next element test = 0; // we still hit a swap, so the sort // isn't done. reset test condition } } } And that's all there is to it. When all the elements are in their proper order, the test condition will not be reset to 0, and the while() loop will terminate. This might make it more readable: int swap, sorting, next, present; do { sorting = 0; for(present = 0; present < (MAX - 1); present++) if(table[present] < table[next = (present + 1)]) { swap = table[present]; table[present] = table[next]; table[next] = swap; sorting = 1; } } while(sorting); Using a slightly more wordy presentation, or copious commentary, can help you when you try to read someone else's code, or try to read your own after not seeing it for an extended period. What is perfectly clear at the time may be obfuscated in retrospect. Running the for(;;) loop from MAX to 1 will sort them in reverse order, assuming next - (present - 1), as will reversing the conditional in the if(). I actually favor running it backwards, myself... int swap, sorting, next, present; do { sorting = 0; for(present = MAX - 1; present > 1; present--) if(table[present] > table[next = (present - 1)]) { swap = table[present]; table[present] = table[next]; table[next] = swap; sorting = 1; } } while(sorting); A minor point, removing a math operation from the for(;;). --- > ] Remain calm and think. I will help you. - Kwai Chang CPUfan. --- * Origin: *YOPS ]I[* 3.1 GIG * RA/FD/FE RADist * Milwaukee, WI (1:154/750) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: F1K00014 Date: 01/14/98 From: ED KOON Time: 09:17pm \/To: ALL (Read 1 times) Subj: Telnet Accessable Fidonet BBS! Greetings All! Just a quick plug for my bbs! Lost your favorite Fidonet BBS? I toss the complete Fidonet Backbone! Access is Free! Access it from anywhere with Telnet! or Http in with your favorite browser! Free Instant Access! No Bothersome Call Back Verifier! Telnet to docsplace.dyn.ml.org 10 Cd Roms online too! Running Winserver! Enjoy! Ed Koon -=DOC=- Webmaster! ============================================================================ Cheers From The Droolers! Ed Koon -=DOC=- Sysop & General Website Slave. Doc's Place Online. Free Adult Access. In Sunny Clearwater Fla (USA!) Email: edkoon@docsplace.dyn.ml.org Member of COCA & Droolnin Proud Of It!! ============================================================================ Fidonet=1:3603/140 Droolnet=85:360/50 Catnet=169:360/140 Icq=2248697 Internet Access http://docsplace.dyn.ml.org | telnet://docsplace.dyn.ml.org Inbound Ftp is also avalible for Fast File Access ftp://docsplace.dyn.ml.org ============================================================================ ... Doc's Place Online. telnet://docsplace.dyn.ml.org --- Platinum Xpress/Win/Wildcat5! v2.0 * Origin: Fido Mail & Adult! http://docsplace.dyn.ml.org Ftp (1:3603/140) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: F1K00015 Date: 01/15/98 From: BRIAN WOOD Time: 04:27pm \/To: VICTOR KEMP (Read 1 times) Subj: converting char to string -=> Quoting Brian Wood to Victor Kemp <=- BW> Maybe this would work, but there are probaly several right answers. BW> BW> int t=strlen(stringvar); BW> if(t stringvar[t]=charvar; /* put charvar on the end */ BW> stringvar[t+1]='\0'; /* keep it a string! */ BW> } BW> else BW> /* some error message, stringvar is full! */ Actually, I think that could overwrite stringvar too, since we're going to add 2 characters to the end of it, accounting for the null. Probably best to use if(t TOPIC: 203 C++ Ref: F1K00016 Date: 01/15/98 From: HERBERT BUSHONG Time: 09:46am \/To: VICTOR KEMP (Read 1 times) Subj: converting char to string ::> I would like to concatenate a single char onto the end of a string but it ::> it can't convert int to char * when I do this: ::> char charvar; ::> char stringvar[90]; ::> strcat(stringvar, charvar); Your charvar is not NUL terminated so strcat won't work. char charvar; char stringvar[90]; char stringret[91]; sprintf(stringret, "%s%c", stringvar, charvar); # Herbert Bushong harchon@centuryinter.net [TEAM OS/2] - Blackbeard's BBS Intelec: 239:600/0 + Fido: 1:19/19 http://www.intelec.com/software/ --- RM 1.31 2508 Raw Data: A naked android. * Origin: Blackbeard's BBS - Ville Platte, LA - 318-468-3385 (1:19/19)