reverse a CArray

Just started using CList and CArray and I'm trying to reverse the order of a
CArray with the code below.  It appears to have no effect and I don't see
why...  Any clues?


<code>
      CArray<CString, CString&> tmp;

      tmp.Add(CString("1"));

      tmp.Add(CString("2"));

      tmp.Add(CString("3"));



      int count = tmp.GetCount();

      for(int i = 0; i < count; i++)

      {

            OutputDebugString(tmp[i]);

            OutputDebugString("\n");

      }



      for(int i = 0; i < count; i++)

      {

            CString buff      = tmp[i];

            tmp[i]            = tmp[(count-1)-i];

            tmp[(count-1)-i]  = buff;

      }



      OutputDebugString("reversed\n");

      for(int i = 0; i < count; i++)

      {

            OutputDebugString(tmp[i]);

            OutputDebugString("\n");

      }

</code>


here is what it prints
1

2

3

reversed

1

2

3


0
sss1 (24)
2/1/2005 9:17:44 PM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
506 Views

Similar Articles

[PageSpeed] 58

news,

>       for(int i = 0; i < count; i++)
>
>       {
>
>             CString buff      = tmp[i];
>
>             tmp[i]            = tmp[(count-1)-i];
>
>             tmp[(count-1)-i]  = buff;
>
>       }

This code is flawed. For each byte reversed, it is then reversed again when
the item's counterpart is reached.

Try something like this instead:

int i, j;

for (i = 0, j = count - 1; i < j; i++, j--)
{
   CString sTemp = tmp[i];
   tmp[i] = tmp[j];
   tmp[j] = sTemp;
}

-- 
Jonathan Wood
SoftCircuits
http://www.softcircuits.com
Available for consulting: http://www.softcircuits.com/jwood/resume.htm

"news.microsoft.com" <sss@sss.com> wrote in message
news:ebgDsNKCFHA.3368@TK2MSFTNGP10.phx.gbl...
> Just started using CList and CArray and I'm trying to reverse the order of
a
> CArray with the code below.  It appears to have no effect and I don't see
> why...  Any clues?
>
>
> <code>
>       CArray<CString, CString&> tmp;
>
>       tmp.Add(CString("1"));
>
>       tmp.Add(CString("2"));
>
>       tmp.Add(CString("3"));
>
>
>
>       int count = tmp.GetCount();
>
>       for(int i = 0; i < count; i++)
>
>       {
>
>             OutputDebugString(tmp[i]);
>
>             OutputDebugString("\n");
>
>       }
>
>
>
>       for(int i = 0; i < count; i++)
>
>       {
>
>             CString buff      = tmp[i];
>
>             tmp[i]            = tmp[(count-1)-i];
>
>             tmp[(count-1)-i]  = buff;
>
>       }
>
>
>
>       OutputDebugString("reversed\n");
>
>       for(int i = 0; i < count; i++)
>
>       {
>
>             OutputDebugString(tmp[i]);
>
>             OutputDebugString("\n");
>
>       }
>
> </code>
>
>
> here is what it prints
> 1
>
> 2
>
> 3
>
> reversed
>
> 1
>
> 2
>
> 3
>
>


0
jwood (1291)
2/1/2005 9:35:42 PM
"Jonathan Wood" <jwood@softcircuits.com> wrote in message
news:%23lcFEYKCFHA.3592@TK2MSFTNGP09.phx.gbl...
> news,
>
> >       for(int i = 0; i < count; i++)
> >
> >       {
> >
> >             CString buff      = tmp[i];
> >
> >             tmp[i]            = tmp[(count-1)-i];
> >
> >             tmp[(count-1)-i]  = buff;
> >
> >       }
>
> This code is flawed. For each byte reversed, it is then reversed again
when
> the item's counterpart is reached.
>
> Try something like this instead:
>
> int i, j;
>
> for (i = 0, j = count - 1; i < j; i++, j--)
> {
>    CString sTemp = tmp[i];
>    tmp[i] = tmp[j];
>    tmp[j] = sTemp;
> }
>
> -- 
> Jonathan Wood
> SoftCircuits
> http://www.softcircuits.com
> Available for consulting: http://www.softcircuits.com/jwood/resume.htm

Thanks Jonathan,
That was very sloppy of me, I see the prob.

Thanks for taking the time!
Steve


>
> "news.microsoft.com" <sss@sss.com> wrote in message
> news:ebgDsNKCFHA.3368@TK2MSFTNGP10.phx.gbl...
> > Just started using CList and CArray and I'm trying to reverse the order
of
> a
> > CArray with the code below.  It appears to have no effect and I don't
see
> > why...  Any clues?
> >
> >
> > <code>
> >       CArray<CString, CString&> tmp;
> >
> >       tmp.Add(CString("1"));
> >
> >       tmp.Add(CString("2"));
> >
> >       tmp.Add(CString("3"));
> >
> >
> >
> >       int count = tmp.GetCount();
> >
> >       for(int i = 0; i < count; i++)
> >
> >       {
> >
> >             OutputDebugString(tmp[i]);
> >
> >             OutputDebugString("\n");
> >
> >       }
> >
> >
> >
> >       for(int i = 0; i < count; i++)
> >
> >       {
> >
> >             CString buff      = tmp[i];
> >
> >             tmp[i]            = tmp[(count-1)-i];
> >
> >             tmp[(count-1)-i]  = buff;
> >
> >       }
> >
> >
> >
> >       OutputDebugString("reversed\n");
> >
> >       for(int i = 0; i < count; i++)
> >
> >       {
> >
> >             OutputDebugString(tmp[i]);
> >
> >             OutputDebugString("\n");
> >
> >       }
> >
> > </code>
> >
> >
> > here is what it prints
> > 1
> >
> > 2
> >
> > 3
> >
> > reversed
> >
> > 1
> >
> > 2
> >
> > 3
> >
> >
>
>


0
sss1 (24)
2/1/2005 10:22:02 PM
Reply:

Similar Artilces:

Dual boot in reverse
Hello, I have dual boot system: driveC --> WinXP driveD --->Vista Now, I do not need WinXP anymore. I want to have only Vista and combine C & D into one, single partition. How to do that without reinstalling Vista? Your thoughts appreciated, Claire On Sun, 17 Jan 2010 15:00:12 -0500, "Claire" <replyto@fra> wrote: >Hello, > I have dual boot system: >driveC --> WinXP >driveD --->Vista >Now, I do not need WinXP anymore. >I want to have only Vista and combine C & D into one, single partition. &...

REVERSING TEXT
HOW CAN I REVERSE TEXT AND PICTURES ON PUBLISHER TO PRINT ONTO T.SHIRTS spike <spike@discussions.microsoft.com> was very recently heard to utter: > HOW CAN I REVERSE TEXT AND PICTURES ON PUBLISHER TO PRINT ONTO > T.SHIRTS YES. PLEASE READ REPLY TO YOUR FIRST POST. Please do not talk in all caps. It is considered shouting and makes your post difficult to read and is rude. Your first message ("how do i reversie pictures and text for printing to t.shirts") is directly below this one and has been answered by yours truly. -- Ed Bennett - MVP Microsoft Publisher ...

Formulas reversed
Using Office 2007 and windows XP. The back slash has become "multiply" and the star has become "divide". In other words, these two symbols are reversed. Have no idea how this happened. How can it be reversed back to normal? thanks. Please give an example of formula, values of input cells and result of formula -- Kind regards, Niek Otten Microsoft MVP - Excel "RENEE" <RENEE@discussions.microsoft.com> wrote in message news:C56D666E-70CD-4E8F-97F9-1FAD9CE92024@microsoft.com... > Using Office 2007 and windows XP. The back slas...

Reverse engineering
I have to document an Access 97 that has grown like wild blackberries. The database's creator has left us no documentation at all and I would like Visio to extract as much information as possible. So far I have extracted a good UML of the tables. Currently I am doing screen dumps of the forms to show what the screens look like - then pasting them into Visio. What else can I do? Can I extract the queries, forms, reports, macros and modules also - and save and print these out from Visio? Please advise. As I remember there was a "database documenter" with Access. I don...

Reverse arrow for hyperlinks
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel I need to find a 'reversing arrow' that I can add to the toolbar to click on after using a hyperlink. <br> You can do this in Windows but I cannot find a similar facility when using my macbook. <br> I use longish word docs that often have links to other parts of the document. How do I get back to the point at which I activated the hyperlink, apart from scrolling back laboriously? <br> Thanks for any solutions. Shift + F5, provided you have not closed the document. Shift + F5 tak...

Possible to reverse a row of entries?
Is there a command or format command that will let me take a row of entries and reverse them? In other words if I have rows #1 through #10 top to bottom, I now want them to go #10 to #1 top to bottom. thanks Rick Hi in B1 enter =OFFET($A$10,-(ROW()-1),0) and copy down for ten rows -- Regards Frank Kabel Frankfurt, Germany rs wrote: > Is there a command or format command that will let me take a row of > entries and reverse them? In other words if I have rows #1 through > #10 top to bottom, I now want them to go #10 to #1 top to bottom. > > thanks > > Rick Ric...

Can I reverse the order of data in a set of cells?
I have a column of cells filed with data. I know I can transpose the data 90 degrees, but is there a way to cut or copy the data in the cells and paste it so the values are in the opposite order, i.e. a 180 degree difference? Thanks to anyone who can help. I am using Excel 2003. One way, insert a new column or use an existing, number it from 1 - n (where n is the last index value you want to reverse the order of, so if your column is 100 rows number the help column 1, 2, 3 - 100) select both columns and sort descending on the help column -- Regards, Peo Sjoblom "salwitt"...

Reversal encryption
Hello, I need a good algorithm for encrypting some vital information about my app in an INI file. I have a class for MD5, but it's not reversible. I'd like to use a private or public key to decrypt the text. By the way, what's the difference between private and public key when we talk about encryption? Sugestions, please? I have googled about the public key encryption and found that CryptoAPI is used frequently. Is this API part of the Windows? If not, what I need to use it? "Jeova Almeida" <jeovaalmeida@yahoo.com> escreveu na mensagem news:e1uwDhuTJHA...

Reverse List?
Greetings! What's happening with the reverse list as of late? It seems like it's not updating anymore since the contacts that I add are never displayed. I have tested this by using my primary account to add my secondary account and then accepting the invitation on the secondary account, my secondary account (target) could see my primary account (source) in the list, but my primary account could not see my secondary account, and both had each other in their contact lists. Thanks in advance; -- jps Greetings jps, I have no real fix for you, but I can confirm...

Customer EFT Reversal
In GP 10, we're getting ready to start using Electronic Funds Transfer in our Receivables area, i.e, we're going to take our customers' payments directly from their bank accounts. If there's a problem where we take a customer's money in error, how do we put it back into their back account using EFT? Thanks! Mary Fetsch ...

How do I reverse this?
Somehow I've managed to turn off the automatic capitalisation at the start of a new sentence only. It was working fine until I accidentally clicked something with my mouse and now the feature has gone!! This is really annoying. I've done the Tools-Options-Spelling thing, though, and everything seems to be the same as it was before!! Any ideas??? Thanks, Pip "Pip" <Pip@discussions.microsoft.com> wrote in message news:A807C07E-502F-4D82-ACD8-FAFE2917EB3D@microsoft.com... > Somehow I've managed to turn off the automatic capitalisation at the > start ...

Reverse of export to database
Ave, I would like to generate a Visio drawing starting from an Access database which contains the results of an 'export to database' of an existing drawing. I found import possibilities from Excel, csv, txt files, but not from databases. I'm using Visio 2002 Professional. Greetings, Are you trying to import the data from the database tables or the database schema? If it is the database schema, run the Database modeling template (File \ New \ Database \ Database model diagram) If you want to get the data, try the "Link to Database" dialog (Tools \ Macros \ Visio Extras...

My printer is printing in reverse. How do i turn it off?
I have tried - properties, advanced, mirror image off. It works once and then goes back to mirror image. How do I turn it off permenantly? Please Change the printer Properties from Start | Settings | Printers and Faxes. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org "lindylou2" <lindylou2@discussions.microsoft.com> wrote in message news:9B714C97-D395-49DC-87BC-67184A8A4736@microsoft.com... >I have tried - properties, advanced, mirror image off. It works once and > then goes back to mirror image...

reverse a CArray
Just started using CList and CArray and I'm trying to reverse the order of a CArray with the code below. It appears to have no effect and I don't see why... Any clues? <code> CArray<CString, CString&> tmp; tmp.Add(CString("1")); tmp.Add(CString("2")); tmp.Add(CString("3")); int count = tmp.GetCount(); for(int i = 0; i < count; i++) { OutputDebugString(tmp[i]); OutputDebugString("\n"); } for(int i = 0; i < count; i++) { ...

CListView icons in *reverse* order with XP commctrl 6??? #2
hi there i have a CListView derived window in my app, which i have set to Icon Mode, and i sort my items alphabetically now it all works fine, except when i include the manifest for using the XP commctrl6 lib, this listview displays the icons in *revrese* alphabetical order, and, now this is the crazy bit, they are displayed from the bottom up!!!! ie, if without the manifest they are displayed as: iconA iconB iconC iconD iconE iconF iconG then they are displayed with the manifest as: iconG iconD iconE iconF iconA iconB iconC *and*, they are placed from the *bottom* of the view window u...

Reverse Worksheet
Somehow I have reversed my worksheets? the A1 cell is in the Top-Right corner. How do I get it back to the Top-Left corner? Hi John tools / options / international - choose left to right under default direction Cheers julieD "John Wolfe" <John Wolfe@discussions.microsoft.com> wrote in message news:DEAD5A71-C86B-4869-866D-E2AD513C9A20@microsoft.com... > Somehow I have reversed my worksheets? the A1 cell is in the Top-Right > corner. How do I get it back to the Top-Left corner? ...

reverse lookup for my exchange server..............
I am using Exchange 2003 (name riley) on win 2003 AD domain controller. When I setup my AD, I used abc.com as my domain name. I figured it not a problem since I am only using it locally. I can send and receive e-mails with no problem. Now, since many are using reverse lookup to filter out spam e-mail, I am in trouble. When you do an nslookup for my exchange server from your server, it comes up as riley.abc.com with an IP address that belongs to abc.com (which is another website that does not belong to us). E-mails are being rejected by those who use reverse lookup because it does not match. ...

CArray help
Hello, I am struggling to learn the concept of template language and the usage of CArray. I have found the CArray declaration in the afxtempl.h file and I have managed to compile with no errors the apparent construction of CArray(MyStructType); But I don't really understand what next to do with it. I am having a mental block with understanding the template declaration of template<class TYPE, class ARG_TYPE> What exactly is this saying ? The constructor is just CArray( ); My compiler docs don't seem to have much on CArray except a listing of it's class members. I...

Reversing chart
http://www.dbconsult.dk/ms/diagram.jpg shows a diagram and its data. The A-columnt holds the months for the label at x-axis. (5th month and 6 months backward). The D-column (g/kWh) holds the actual data for the diagram. This part is fine. However, it is more intuitive to have the oldest month shown first (most left) in the diagram. So that the diagram from left to right shows the months 12 to 5, showing past to present. Is it possible to have the data shown as they are, but have the chart to reverse the months? Regards /Snedker -- http://www.dbconsult.dk http://www.vinthervej2.dk [privat...

reverse list
For some time now the reverse list isn't updated. Many people experience this. Strange thing is, there is no answer at all about a fix. I wrote several mails to windows live support and got no answer. Why is microsoft being so mysterious about this problem? Can we expect a fix for the current version or do we have to wait for the new version? Greetings Ben, I do believe it's a server-side problem. -- Jonathan Kay Microsoft MVP - Windows Live Messenger MSN Messenger/Windows Messenger MessengerGeek Blog: http://www.messengergeek.com Messenger Resources: http://messe...

Why are my columns and rows reversed when I open Excel
When I open my Excel spreadsheet the columns, rows and scroll bars are reversed?? What's happened? Tools|options|International Tab Uncheck that "view current sheet right-to-left" Deb Web wrote: > > When I open my Excel spreadsheet the columns, rows and scroll bars are > reversed?? What's happened? -- Dave Peterson ...

Reverse Find and Replace ?
Hi, I'm wanting to Reverse find and replace a particular character in a Powershell string. e.g. reverse find "b" in "abcabc" and replace with "d" to give "abcadc". Could someone please advise how this could be achieved ? Thanks, Patrick Sorry - also should have stated that just the first instance of a particular character should be replaced. On Jan 8, 11:23=A0am, Patrick <prynh...@gmail.com> wrote: > Hi, > > I'm wanting to Reverse find and replace a particular character in a > Powershell string. =A0e.g. r...

reversing date
Default the reversing date on the GL Transaction Entry window to be the 1st or last day in the next fiscal period. It currently default to the transaction date, and if the user posts, then the JE is immediately reversed in the same period. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" ...

Outlook Problem
I am using Outlook 2000, with an active and archive files (outlook.pst and archive.pst files). Everything wa OK until yesterday, when a family member was messing around with my Outlook data. It now appears that these 2 data diles are being used by the Outlook application program in opposite ways, ie, the archive file appears to be active, and the outlook.pst file appears to be the archive file. Specific characteristics are as follows: 1) On the top of the "Outlook Today" page, it used to show "Personal Folders - Outlook Today". Now it shows on the top of the page &...

reversing color
I have a logo for my basketball team. the bacground is red with a white star in the middle. Inside the star is a red DT logo. How can I change what is red to white and what is white to red With a graphics program. Even Paint would work. -- JoAnn Paules MVP Microsoft [Publisher] ~~~~~ How to ask a question http://support.microsoft.com/KB/555375 "rosteph" <rosteph@discussions.microsoft.com> wrote in message news:437EEC05-AEAB-47EF-929A-753E97BDC6AC@microsoft.com... >I have a logo for my basketball team. the bacground is red with a white >star > in the middl...