Click here to Skip to main content
15,890,557 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Will do this generate a memory leak? Pin
Gary R. Wheeler31-Dec-06 1:22
Gary R. Wheeler31-Dec-06 1:22 
AnswerRe: Will do this generate a memory leak? Pin
Gary R. Wheeler31-Dec-06 1:25
Gary R. Wheeler31-Dec-06 1:25 
AnswerRe: Will do this generate a memory leak? Pin
toxcct31-Dec-06 2:15
toxcct31-Dec-06 2:15 
AnswerYes, if the caller doesn't delete the pointer. Pin
CPallini31-Dec-06 6:58
mveCPallini31-Dec-06 6:58 
Questionno_input comes into reality Pin
davvid30-Dec-06 23:15
davvid30-Dec-06 23:15 
Answerjust a guess Pin
toxcct31-Dec-06 2:27
toxcct31-Dec-06 2:27 
GeneralRe: just a guess Pin
davvid31-Dec-06 2:46
davvid31-Dec-06 2:46 
AnswerRe: no_input comes into reality Pin
CPallini31-Dec-06 11:02
mveCPallini31-Dec-06 11:02 
The problem is in the following initialization:
struct
{
   char face;
    unsigned int value;
}
card[13] =
{    {'2', 2},{'2', 3},{'2', 4},
    {'5', 5},{'6', 6},{'7', 7},
    {'8', 8},{'9', 9},{'10', 10},
    {'J', 10},{'Q', 10},{'K', 10},
    {'A', 1}
};


since you have declare the struct to hold a char plus
an unsigned int. This works fine for all elements but {'10',10} does not match the struct because '10' isn't a character constant, but a multicharacter constant (see MSDN, C++ Character Constants topic, i.e. a 16-bits number that does not fit inside the struct face member (the compiler warns about). What occurs is a cast of the 16-bits value (i.e. a truncation) '10'<->0x3130 to the corrensponding character value '0'<->0x30.
To fix the bug you can either choose a (really) single character to represent 10(e.g. 'X') or change the struct to hold strings, e.g.

struct
{
   char * sFace;
    unsigned int value;
}
card[13] =
{    {"2", 2},{"2", 3},{"2", 4},
    {"5", 5},{"6", 6},{"7", 7},
    {"8", 8},{"9", 9},{"10", 10},
    {"J", 10},{"Q", 10},{"K", 10},
    {"A", 1}
};



hope that helps.
Smile | :)

If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.

QuestionIE7 settings Pin
Waldermort30-Dec-06 20:52
Waldermort30-Dec-06 20:52 
AnswerRe: IE7 settings Pin
Michael Dunn30-Dec-06 21:50
sitebuilderMichael Dunn30-Dec-06 21:50 
QuestionHow do I have a &quot;Splitter Functionality&quot; without using CSplitterWind ? [modified] Pin
erajsri30-Dec-06 18:32
erajsri30-Dec-06 18:32 
AnswerRe: How do I have a &quot;Splitter Functionality&quot; without using CSplitterWind ? Pin
Mark Salsbery31-Dec-06 5:43
Mark Salsbery31-Dec-06 5:43 
GeneralRe: How do I have a &amp;quot;Splitter Functionality&amp;quot; without using CSplitterWind ? Pin
erajsri31-Dec-06 15:36
erajsri31-Dec-06 15:36 
AnswerRe: How do I have a &quot;Splitter Functionality&quot; without using CSplitterWind ? Pin
Cristian Amarie2-Jan-07 4:03
Cristian Amarie2-Jan-07 4:03 
Questionunary minus in backwards for-loop question [modified] Pin
FocusedWolf30-Dec-06 17:00
FocusedWolf30-Dec-06 17:00 
AnswerRe: unary minus in backwards for-loop question Pin
Michael Dunn30-Dec-06 18:16
sitebuilderMichael Dunn30-Dec-06 18:16 
AnswerRe: unary minus in backwards for-loop question Pin
John M. Drescher30-Dec-06 18:17
John M. Drescher30-Dec-06 18:17 
GeneralRe: unary minus in backwards for-loop question Pin
FocusedWolf30-Dec-06 19:07
FocusedWolf30-Dec-06 19:07 
QuestionHow to get a dialog size by ID? Pin
hanlei000000000930-Dec-06 16:01
hanlei000000000930-Dec-06 16:01 
AnswerRe: How to get a dialog size by ID? Pin
hanlei000000000930-Dec-06 16:14
hanlei000000000930-Dec-06 16:14 
AnswerRe: How to get a dialog size by ID? Pin
prasad_som1-Jan-07 17:24
prasad_som1-Jan-07 17:24 
QuestionNeed some help working with JPEGs... Pin
CoffeeAddict1930-Dec-06 12:06
CoffeeAddict1930-Dec-06 12:06 
AnswerRe: Need some help working with JPEGs... Pin
Joe Woodbury30-Dec-06 15:03
professionalJoe Woodbury30-Dec-06 15:03 
AnswerRe: Need some help working with JPEGs... Pin
Hamid_RT31-Dec-06 5:49
Hamid_RT31-Dec-06 5:49 
AnswerRe: Need some help working with JPEGs... Pin
Mark Salsbery31-Dec-06 5:56
Mark Salsbery31-Dec-06 5:56 

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.