| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Heres another pgm with the same errors. Do you think it could be my C++.Net Settings
One of the problems related to the manipulation of expressions is the transformation of expressions from infix notation
to postfix notation. In infix notation the operations of the expressions are placed in between the operands (e.g., a + b); this is the “standard” way of writing expressions: a + b * c – d In postfix notation instead the operands are written first and the operation is written after (e.g., a b +). Computers don’t like infix notations: infix notation requires the use of parenthesis in order to control the order of execution of the different operations. This is not the case in postfix notation—each expression can be unambiguously written without the use of parenthesis. For example, the expression a* b - (c + d) + e is represented in postfix notation as a b * c d + - e + Given an expression in postfix notation, it is easy to develop an algorithm which evaluates the expression, making use of a stack. The idea is that the expression is read from left to right; each operand is pushed on the stack; each time an operation is encountered, this is applied to the two top elements of the stack (which are popped), and the result is pushed back on the stack. For example, the postfix expression 2 4 6 + * (which represents the expression 2 * (4 + 6)) is evaluated as in the following figure: Expression Stack 2 4 6 + * 4 6 + * 2 6 + * 2 4 + * 2 4 6 * 2 10 20 This program evaluates a postfix expression using static stack operations #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define MAX 10 typedef struct stack_format *Stack; typedef struct stack_format { int count; float *space; } basic_stack; Stack Init() { Stack new1; new1=(basic_stack *)malloc(sizeof(basic_stack)); new1->count = 0; new1->space = (float *)malloc(sizeof(float)*MAX); return new1; } void Push(float c, Stack l) { if (l->count == MAX) return; l->space[l->count] = c; l->count++; } void Pop(int index, Stack l) { if (l->count == 0) return; l->count--; } void printStack(Stack l) { for (int i=0; i<l->count-1; i++) printf("%.1f, ", l->space[i]); printf("%.1f", l->space[i]); } void main() { Stack l = Init(); char infix[] = "246+*324/*+", val[1]; printf( "Current Stack\t\t\t Necessary Operation" ); for (int i = 0; i < strlen(infix); i++ ) { if (isdigit(infix[i])) { val[0] = infix[i]; Push(atof(val),l); puts("\n"); } if (!(isdigit(infix[i]))) { float val1 = l->space[l->count-2], val2=l->space[l->count-1], val; int oper = infix[i]; if (oper == '+') val = val1+val2; if (oper == '-') val = val1-val2; if (oper == '*') val = val1*val2; if (oper == '/') val = val1/val2; Pop(i-1, l); Pop(i-1, l); Push(val, l); for (int j = 0; j < 7-l->count; j++ ) if ( l->space[j] >= 10 ) printf(" "); else printf(" "); printf("(%.1f %c %.1f = %.1f)\n", val1, oper, val2, val); } printStack(l); } puts("\n"); } BUILD ERROR TASKS RECORDED!! postfixexpression error LNK2019: unresolved external symbol _WinMain@16 referenced in function _WinMainCRTStartup |
|
#2
|
|||
|
|||
|
Regarding the error you're getting it looks like you have set the project settings to an Windows application. But you're program is a commandline application....
Start a new project and select Commandline application. You can also select that a cpp file is generated ("Hello World"). Continue from this part by pasting your code. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Heres another pgm with the same errors. Do you think it could be my C++.Net Settings |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|