Click here to Skip to main content
15,912,897 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Is there a fast method for doing this? Pin
David Crow30-Apr-03 3:23
David Crow30-Apr-03 3:23 
GeneralRe: Is there a fast method for doing this? Pin
chen30-Apr-03 3:35
chen30-Apr-03 3:35 
GeneralRe: Is there a fast method for doing this? Pin
David Crow30-Apr-03 6:03
David Crow30-Apr-03 6:03 
GeneralRe: Is there a fast method for doing this? Pin
chen30-Apr-03 6:18
chen30-Apr-03 6:18 
GeneralRe: Is there a fast method for doing this? Pin
Rage30-Apr-03 6:19
professionalRage30-Apr-03 6:19 
AnswerRe: Is there a fast method for doing this? Pin
Sean Cundiff30-Apr-03 5:14
Sean Cundiff30-Apr-03 5:14 
GeneralRe: Is there a fast method for doing this? Pin
chen30-Apr-03 5:49
chen30-Apr-03 5:49 
GeneralRe: Is there a fast method for doing this? Pin
David Crow30-Apr-03 5:56
David Crow30-Apr-03 5:56 
By what gauge are you using to measure its current speed?

Why are you only setting the first 28 bytes of backup, which is 60 bytes, to 0?

The only change I could possibly make to this would be something like:

iOne = 0;
for (i = 0; i < length; i++)
{
    if ('1' == backup[i]) 
        iOne++;
}
    
return (length - iOne);

You could actually do this counting in the other 'for' loop. This would save having to iterate through the string again

You could also change the first loop to something like the following, but any gain would be negligible. If this function is only called a few times, this is really a moot exercise.

if ('1' == str[i])
{
    if ('0' == tmp)
        backup[i] = '1';
    else // if ('1' == tmp)
        backup[i] = '0';
}
else // if ('0' == str[i])
{
    if ('0' == tmp)
        backup[i] = '0';
    else // if ('1' == tmp)
        backup[i] = '1';
}

BTW, read the FAQ regarding how to format code when certain reserved symbols are used. The '<' symbol should be "& lt" and the '>' should be "& gt", minus the space. This is evident in the 'for' loop of your code.
GeneralRe: Is there a fast method for doing this? Pin
Anonymous30-Apr-03 9:05
Anonymous30-Apr-03 9:05 
GeneralRe: Is there a fast method for doing this? Pin
David Crow30-Apr-03 10:08
David Crow30-Apr-03 10:08 
GeneralRe: Is there a fast method for doing this? Pin
Anonymous1-May-03 7:27
Anonymous1-May-03 7:27 
GeneralRe: Is there a fast method for doing this? Pin
David Crow1-May-03 7:52
David Crow1-May-03 7:52 
GeneralRe: Is there a fast method for doing this? Pin
Anonymous2-May-03 8:10
Anonymous2-May-03 8:10 
GeneralRe: Is there a fast method for doing this? Pin
David Crow2-May-03 8:24
David Crow2-May-03 8:24 
GeneralA question about IE Pin
Carlos Antollini30-Apr-03 2:52
Carlos Antollini30-Apr-03 2:52 
GeneralRe: A question about IE Pin
Anonymous30-Apr-03 3:10
Anonymous30-Apr-03 3:10 
GeneralRe: A question about IE Pin
Stephane Rodriguez.30-Apr-03 3:17
Stephane Rodriguez.30-Apr-03 3:17 
GeneralProblem with CRecordSet Pin
Poul Haahr Klemmensen30-Apr-03 1:46
Poul Haahr Klemmensen30-Apr-03 1:46 
GeneralRe: Problem with CRecordSet Pin
David Crow30-Apr-03 2:50
David Crow30-Apr-03 2:50 
GeneralRe: Problem with CRecordSet Pin
Poul Haahr Klemmensen30-Apr-03 2:59
Poul Haahr Klemmensen30-Apr-03 2:59 
GeneralSTL algorithm Pin
Rage30-Apr-03 1:36
professionalRage30-Apr-03 1:36 
GeneralRe: STL algorithm Pin
markkuk30-Apr-03 2:10
markkuk30-Apr-03 2:10 
GeneralRe: STL algorithm Pin
Rage30-Apr-03 5:42
professionalRage30-Apr-03 5:42 
GeneralRe: STL algorithm Pin
User 988530-Apr-03 2:18
User 988530-Apr-03 2:18 
GeneralRe: STL algorithm Pin
Rage30-Apr-03 5:42
professionalRage30-Apr-03 5:42 

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.