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

C / C++ / MFC

 
GeneralRe: Same Resource IDs in resource.h Pin
Anu_Bala15-Feb-11 21:46
Anu_Bala15-Feb-11 21:46 
AnswerRe: Same Resource IDs in resource.h Pin
chevu15-Feb-11 22:01
chevu15-Feb-11 22:01 
GeneralRe: Same Resource IDs in resource.h Pin
ThatsAlok15-Feb-11 22:52
ThatsAlok15-Feb-11 22:52 
GeneralRe: Same Resource IDs in resource.h Pin
Anu_Bala15-Feb-11 22:54
Anu_Bala15-Feb-11 22:54 
QuestionArray Issue. Pin
Mike Certini15-Feb-11 19:13
Mike Certini15-Feb-11 19:13 
AnswerSolution To Array Issue. Pin
Mike Certini15-Feb-11 20:07
Mike Certini15-Feb-11 20:07 
AnswerRe: Array Issue. Pin
User 742933815-Feb-11 20:07
professionalUser 742933815-Feb-11 20:07 
AnswerRe: Array Issue. Pin
Stefan_Lang16-Feb-11 0:18
Stefan_Lang16-Feb-11 0:18 
Your while loop initializes the array roll with values between 1 and 10. Note that there is no guarantee every value between 1 and 10 will actually be stored in roll somewhere; for all you know it might be an array full of 1s or full of 10s!

In your first for loop you increment loop num times, then access roll[loop+1]; on the last loop you will read past the end of the array, invalidating the comparison, so if the biggest value in your array happens to be stored in the last element, it may or may not be stored in temp. In Debug this probably won't cause a problem, as likely roll[100] would just access fin[0] instead, and that would be initialized to 0. In Release mode however there is no guarantee that the array fin will be initialized to 0 - in my experience it most likely will not.

The intention of the first for loop appears to be to find the largest value in roll and store it in temp. Note that this value may be anything between 1 and 10!

The error you noticed, however, is due to what the others already pointed out above: you shouldn't increment cyc in the outer loop! What happens is this: the inner loop finds all items in roll that correspond to the temp value, store it in fin, and increment (correctly) the index cyc. Once you're at the end of the loop, temp gets decremented, then cyc gets incremented again, causing the gap you noticed, then you go on searching for occurences of your now decreased value of temp.

The reason for this confusion is that the outer loop is really all about temp, not cyc! The clearest way to write your last loop would be like this:
cyc = 0;
for (int compare = temp; compare > 0; compare--) {
   for (loop = 0; loop < LIMIT; loop++) {
      if (roll[loop] == compare) {
         fin[cyc] = compare;
         cyc++;
      }
   }
}


Note that I replaced num with LIMIT. This doesn't change anything in your code, but it is easier to read, as a reader unfamiliar with your code doesn't have to interpret all of it just to find out what value num would hold. Also it's less likely to accidentally mess up if you later change your code and possibly change the value of num.

Now, while the above is clearer, it is also potentially less efficient; you used the condition cyc < num, which would lead the outer loop to terminate, even if temp is still > 0, e.g. when there are no 1s in the array roll. So you could replace compare > 0 in the above loop with cyc < num, or, preferably, cyc < LIMIT.

You could of course also avoid the introduction of yet another variable (compare) and just write the outer for loop like this, trading clarity for shorter, and potentially more efficient, code:
for (cyc = 0; cyc < LIMIT; temp--) {
   //... (use temp in comparison instead of compare)
}

QuestionClosing childview in MDI [SOLVED] Pin
Anu_Bala15-Feb-11 18:23
Anu_Bala15-Feb-11 18:23 
AnswerRe: Closing childview in MDI Pin
tagopi15-Feb-11 18:53
tagopi15-Feb-11 18:53 
AnswerRe: Closing childview in MDI Pin
_AnsHUMAN_ 15-Feb-11 19:02
_AnsHUMAN_ 15-Feb-11 19:02 
AnswerRe: Closing childview in MDI Pin
Anu_Bala15-Feb-11 20:01
Anu_Bala15-Feb-11 20:01 
QuestionHow to bring an App to front, from another App Pin
timbk15-Feb-11 15:50
timbk15-Feb-11 15:50 
QuestionRe: How to bring an App to front, from another App Pin
David Crow15-Feb-11 16:54
David Crow15-Feb-11 16:54 
AnswerRe: How to bring an App to front, from another App Pin
Anthony Mushrow15-Feb-11 16:58
professionalAnthony Mushrow15-Feb-11 16:58 
GeneralRe: How to bring an App to front, from another App Pin
timbk16-Feb-11 0:32
timbk16-Feb-11 0:32 
GeneralRe: How to bring an App to front, from another App Pin
Anthony Mushrow16-Feb-11 3:31
professionalAnthony Mushrow16-Feb-11 3:31 
GeneralRe: How to bring an App to front, from another App Pin
timbk16-Feb-11 11:06
timbk16-Feb-11 11:06 
GeneralRe: How to bring an App to front, from another App Pin
Anthony Mushrow16-Feb-11 12:03
professionalAnthony Mushrow16-Feb-11 12:03 
GeneralRe: How to bring an App to front, from another App Pin
timbk16-Feb-11 16:54
timbk16-Feb-11 16:54 
GeneralRe: How to bring an App to front, from another App Pin
Anthony Mushrow16-Feb-11 17:28
professionalAnthony Mushrow16-Feb-11 17:28 
QuestionHow to split the frame as three part? [Solved] Pin
yu-jian15-Feb-11 14:43
yu-jian15-Feb-11 14:43 
AnswerRe: How to split the frame as three part? Pin
Richard MacCutchan15-Feb-11 23:05
mveRichard MacCutchan15-Feb-11 23:05 
QuestionQuestion about CListCtrl Pin
Hans Dietrich15-Feb-11 13:15
mentorHans Dietrich15-Feb-11 13:15 
AnswerRe: Question about CListCtrl Pin
Rolf Kristensen15-Feb-11 14:36
Rolf Kristensen15-Feb-11 14:36 

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.