Click here to Skip to main content
15,925,309 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: clickable bitmap colour problems Pin
b_girl2-Dec-03 8:47
b_girl2-Dec-03 8:47 
GeneralRe: clickable bitmap colour problems Pin
Mike Dimmick27-Nov-03 9:26
Mike Dimmick27-Nov-03 9:26 
GeneralCFileDialog - Reset the last configuration Pin
Denislef27-Nov-03 5:55
Denislef27-Nov-03 5:55 
GeneralActiveX Problem Pin
Java2C#27-Nov-03 5:14
Java2C#27-Nov-03 5:14 
QuestionMost optimized way to reverse a string? Pin
melwyn27-Nov-03 4:38
melwyn27-Nov-03 4:38 
AnswerRe: Most optimized way to reverse a string? Pin
Anonymous27-Nov-03 5:13
Anonymous27-Nov-03 5:13 
GeneralRe: Most optimized way to reverse a string? Pin
melwyn27-Nov-03 5:24
melwyn27-Nov-03 5:24 
AnswerRe: Most optimized way to reverse a string? Pin
Ian Darling27-Nov-03 5:37
Ian Darling27-Nov-03 5:37 
No temps in reverseString at all, and only one loop which goes halfway along the string. It is an in-place reverse, so it overwrites whats there.

If I was feeling really keen I could turn it into a template too Big Grin | :-D

#include <iostream><br />
#include <cstdio><br />
<br />
using namespace std;<br />
<br />
void reverseString(char *str, const int &len)<br />
{<br />
 for(int i=0; i<(len-1)-i; ++i)<br />
  str[i] ^= str[(len-1)-i] ^= str[i] ^= str[(len-1)-i];<br />
}<br />
<br />
int main()<br />
{<br />
 char str[] = "String to reverse!";<br />
 int len = strlen(str);<br />
<br />
 // in place reverse<br />
 cout << str << endl;<br />
 reverseString(str, len);<br />
 cout << str << endl;<br />
 return 0;<br />
}


--
Ian Darling
"The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky
AnswerRe: Most optimized way to reverse a string? Pin
Mike Dimmick27-Nov-03 6:23
Mike Dimmick27-Nov-03 6:23 
GeneralRe: Most optimized way to reverse a string? Pin
Obliterator27-Nov-03 6:39
Obliterator27-Nov-03 6:39 
GeneralRe: Most optimized way to reverse a string? Pin
melwyn28-Nov-03 0:08
melwyn28-Nov-03 0:08 
AnswerRe: Most optimized way to reverse a string? Pin
фил4-Dec-03 21:57
фил4-Dec-03 21:57 
GeneralRe: Most optimized way to reverse a string? Pin
melwyn7-Dec-03 20:08
melwyn7-Dec-03 20:08 
Questionwitch message? Pin
willempipi27-Nov-03 4:33
willempipi27-Nov-03 4:33 
AnswerRe: witch message? Pin
Johnny ²27-Nov-03 4:54
Johnny ²27-Nov-03 4:54 
GeneralRe: witch message? Pin
willempipi27-Nov-03 5:45
willempipi27-Nov-03 5:45 
GeneralRe: witch message? Pin
Ravi Bhavnani27-Nov-03 6:58
professionalRavi Bhavnani27-Nov-03 6:58 
GeneralRe: witch message? Pin
melwyn27-Nov-03 20:21
melwyn27-Nov-03 20:21 
GeneralDLL Help Pin
Obliterator27-Nov-03 3:59
Obliterator27-Nov-03 3:59 
GeneralRe: DLL Help Pin
melwyn27-Nov-03 4:20
melwyn27-Nov-03 4:20 
GeneralRe: DLL Help Pin
Obliterator27-Nov-03 4:57
Obliterator27-Nov-03 4:57 
GeneralRe: DLL Help Pin
Mike Dimmick27-Nov-03 6:30
Mike Dimmick27-Nov-03 6:30 
GeneralRe: DLL Help Pin
Obliterator27-Nov-03 6:36
Obliterator27-Nov-03 6:36 
GeneralRe: DLL Help Pin
melwyn27-Nov-03 23:30
melwyn27-Nov-03 23:30 
GeneralRe: DLL Help Pin
Obliterator28-Nov-03 3:03
Obliterator28-Nov-03 3:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.