Click here to Skip to main content
15,893,486 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: ActiveX question, please help. Pin
Anonymous1-Dec-04 13:04
Anonymous1-Dec-04 13:04 
GeneralRe: ActiveX question, please help. Pin
Wes Aday1-Dec-04 13:05
professionalWes Aday1-Dec-04 13:05 
GeneralOutput from screen to printer Pin
BRIMID1-Dec-04 8:29
BRIMID1-Dec-04 8:29 
GeneralRe: Output from screen to printer Pin
David Crow1-Dec-04 9:52
David Crow1-Dec-04 9:52 
GeneralRe: Output from screen to printer Pin
Mike Danberg1-Dec-04 11:40
Mike Danberg1-Dec-04 11:40 
GeneralRe: Output from screen to printer Pin
Mike Danberg1-Dec-04 11:57
Mike Danberg1-Dec-04 11:57 
GeneralRe: Output from screen to printer Pin
PJ Arends1-Dec-04 12:04
professionalPJ Arends1-Dec-04 12:04 
GeneralCArray RemoveAt Questions Pin
ayajiang1-Dec-04 7:45
ayajiang1-Dec-04 7:45 
Hi all,

I got a really weird problem when I tried to use RemoveAt() function to remove elements from a CArray.

I have two parallel arrays called carrURL (a CString array) and carrHit (an int array). What I want to do is:

If an element in carrURL has duplicated elements, then add its corresponding values from carrHit together and then remove these duplicated elements from carrURL. If an element is unique in the array, just keep it and go next.

For example: suppose carrURL[0], carrURL[4], carrURL [100] are the same string, add the values of carrHit[4], carrHit[100] to carrURL[0] and remove carrURL[4] and carrURL[100] (also remove carrHit[4] and carrHit[100]).

The code is below:

for (int nIndex = 0; nIndex < carrURL.GetSize(); nIndex++){
for (int ncItem = nIndex + 1; ncItem < carrURL.GetSize(); ncItem++){
if (carrURL[ncItem].Compare(carrURL[nIndex]) == 0){
carrHit[nIndex] += carrHit[ncItem];
carrHit.RemoveAt(ncItem);
carrURL.RemoveAt(ncItem);
}
}
carrHit.FreeExtra(); // free extra memory
carrURL.FreeExtra(); // free extra memory
}

However, the result is not what I supposed. It shows something like that:

carrURL carrHit
a 500 -- good
b 333 -- good
c 450 -- weird!
c 61 -- weird!
d 11 -- good
e 10 -- good
c 1 -- weird!

I can't understand why there are still some duplicated values which can not be found out after running a proper loop.

Any suggestions?

Thanks a lot!
GeneralRe: CArray RemoveAt Questions Pin
Ravi Bhavnani1-Dec-04 8:07
professionalRavi Bhavnani1-Dec-04 8:07 
GeneralRe: CArray RemoveAt Questions Pin
ayajiang1-Dec-04 23:44
ayajiang1-Dec-04 23:44 
GeneralRe: CArray RemoveAt Questions Pin
Ravi Bhavnani2-Dec-04 0:09
professionalRavi Bhavnani2-Dec-04 0:09 
GeneralRe: CArray RemoveAt Questions Pin
Maximilien1-Dec-04 8:20
Maximilien1-Dec-04 8:20 
GeneralRe: CArray RemoveAt Questions Pin
ayajiang1-Dec-04 23:45
ayajiang1-Dec-04 23:45 
GeneralRe: CArray RemoveAt Questions Pin
Graham Bradshaw1-Dec-04 9:51
Graham Bradshaw1-Dec-04 9:51 
GeneralRe: CArray RemoveAt Questions Pin
ayajiang1-Dec-04 23:39
ayajiang1-Dec-04 23:39 
GeneralDifference of char * and int * Pin
sacoskun1-Dec-04 7:20
sacoskun1-Dec-04 7:20 
GeneralRe: Difference of char * and int * Pin
Maximilien1-Dec-04 7:25
Maximilien1-Dec-04 7:25 
GeneralRe: Difference of char * and int * Pin
David Crow1-Dec-04 7:25
David Crow1-Dec-04 7:25 
GeneralRe: Difference of char * and int * Pin
namaskaaram1-Dec-04 17:46
namaskaaram1-Dec-04 17:46 
GeneralRe: Difference of char * and int * Pin
sacoskun1-Dec-04 18:57
sacoskun1-Dec-04 18:57 
GeneralCScrollView Odd little Behavior Pin
poiut1-Dec-04 4:58
poiut1-Dec-04 4:58 
GeneralRe: CScrollView Odd little Behavior Pin
poiut1-Dec-04 5:58
poiut1-Dec-04 5:58 
Generaler the option of a MFC Pin
BRIMID1-Dec-04 3:54
BRIMID1-Dec-04 3:54 
GeneralRe: er the option of a MFC Pin
toxcct1-Dec-04 4:45
toxcct1-Dec-04 4:45 
GeneralRe: er the option of a MFC Pin
BRIMID1-Dec-04 5:32
BRIMID1-Dec-04 5:32 

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.