Click here to Skip to main content
15,886,822 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Retrieve HWND of a control that has focus Pin
leon de boer12-Aug-18 3:47
leon de boer12-Aug-18 3:47 
QuestionWhat is the magic incantation to select a row in a CListCtrl in report mode ? Pin
Maximilien9-Aug-18 9:09
Maximilien9-Aug-18 9:09 
GeneralRe: What is the magic incantation to select a row in a CListCtrl in report mode ? Pin
David Crow9-Aug-18 9:47
David Crow9-Aug-18 9:47 
GeneralRe: What is the magic incantation to select a row in a CListCtrl in report mode ? Pin
Maximilien9-Aug-18 12:06
Maximilien9-Aug-18 12:06 
GeneralRe: What is the magic incantation to select a row in a CListCtrl in report mode ? Pin
Maximilien21-Aug-18 5:11
Maximilien21-Aug-18 5:11 
Questionhow to use recursive descent algorithm to compute an arithmetical expression? Pin
tony_ming8-Aug-18 20:42
tony_ming8-Aug-18 20:42 
AnswerRe: how to use recursive descent algorithm to compute an arithmetical expression? Pin
Richard MacCutchan8-Aug-18 20:50
mveRichard MacCutchan8-Aug-18 20:50 
AnswerRe: how to use recursive descent algorithm to compute an arithmetical expression? Pin
Stefan_Lang8-Aug-18 22:07
Stefan_Lang8-Aug-18 22:07 
The logic in your parse functions is flawed: it first looks for the operator, and only then looks for the arguments. This would only work for an expression like "+ 1 2" rather than "1 + 2".

You have to change your code to first split it into tokens and then check the second (and maybe following) token(s) of the remaining part of your expression string for operators, before passing the first token(s) and the rest of the tokens (after the operator) on to the next recursion step.

P.S.: It is always a bad idea to use global variables in a program. But it is especially devastating when using recursive functions! I don't see any reasonable way to implement E(), T() and F() without passing the part of the string that needs to be analyzed. The advantage is that you don't need to split the whole string into tokens up front as I suggested at first. Instead each function just searches its part of the string for the operators that it can interpret, extract the arguments of that operator accordingly, and pass those into further recursive calls.

P.P.S.: example for function E():
C++
double E (const std::string& str) {
   size_t op_pos = str.find_first_of("+-", 1); // search for '+' or '-' starting at the second character of the string
   if (op_pos == std::string::npos) { // not found
      return T(str);
   }

   std::string first_operand = str.substr(0, op_pos);
   std::string second_operand = str.substr(op_pos+1);
   return (str.at(op_pos) == '+')
      ? E(first_operand) + T(second_operand)
      : E(first_operand) - T(second_operand)
}

GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)


modified 9-Aug-18 4:43am.

QuestionRe: how to use recursive descent algorithm to compute an arithmetical expression? Pin
David Crow9-Aug-18 4:55
David Crow9-Aug-18 4:55 
AnswerRe: how to use recursive descent algorithm to compute an arithmetical expression? Pin
CPallini9-Aug-18 10:38
mveCPallini9-Aug-18 10:38 
QuestionMovePrev() throwing 265926 error code (End Of RowsSet). Pin
Sampath5797-Aug-18 20:19
Sampath5797-Aug-18 20:19 
AnswerRe: MovePrev() throwing 265926 error code (End Of RowsSet). Pin
Jochen Arndt7-Aug-18 21:52
professionalJochen Arndt7-Aug-18 21:52 
GeneralRe: MovePrev() throwing -2147217837 error code Pin
Sampath5797-Aug-18 22:23
Sampath5797-Aug-18 22:23 
GeneralRe: MovePrev() throwing 265926 error code (End Of RowsSet). Pin
Jochen Arndt7-Aug-18 23:26
professionalJochen Arndt7-Aug-18 23:26 
GeneralRe: MovePrev() throwing 265926 error code (End Of RowsSet). Pin
Sampath5798-Aug-18 0:01
Sampath5798-Aug-18 0:01 
GeneralRe: MovePrev() throwing 265926 error code (End Of RowsSet). Pin
Jochen Arndt8-Aug-18 0:29
professionalJochen Arndt8-Aug-18 0:29 
GeneralRe: MovePrev() throwing 265926 error code (End Of RowsSet). Pin
Sampath5798-Aug-18 3:19
Sampath5798-Aug-18 3:19 
GeneralRe: MovePrev() throwing 265926 error code (End Of RowsSet). Pin
Jochen Arndt8-Aug-18 3:21
professionalJochen Arndt8-Aug-18 3:21 
GeneralRe: MovePrev() throwing -2147217837 error code. Pin
Sampath57912-Aug-18 1:36
Sampath57912-Aug-18 1:36 
QuestionRe: MovePrev() throwing 265926 error code (End Of RowsSet). Pin
David Crow8-Aug-18 4:45
David Crow8-Aug-18 4:45 
AnswerRe: MovePrev() throwing 265926 error code (End Of RowsSet). Pin
Sampath5798-Aug-18 5:16
Sampath5798-Aug-18 5:16 
QuestionRe: MovePrev() throwing 265926 error code (End Of RowsSet). Pin
David Crow9-Aug-18 4:56
David Crow9-Aug-18 4:56 
AnswerRe: MovePrev() throwing 265926 error code (End Of RowsSet). Pin
Stefan_Lang8-Aug-18 21:44
Stefan_Lang8-Aug-18 21:44 
GeneralRe: MovePrev() throwing -2147217837 error code Pin
Sampath57912-Aug-18 5:29
Sampath57912-Aug-18 5:29 
QuestionMFC Icon indicator (red/green) Pin
Maximilien6-Aug-18 7:20
Maximilien6-Aug-18 7:20 

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.