C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 23rd, 2005, 11:47 PM
unclebuck unclebuck is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 6 unclebuck User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 59 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old October 24th, 2005, 05:49 AM
MichaelSoft MichaelSoft is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Location: The Netherlands
Posts: 121 MichaelSoft User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 20 sec
Reputation Power: 4
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Heres another pgm with the same errors. Do you think it could be my C++.Net Settings


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway