?
Solved

why it wont running and why there is redeclaration of errorcheck?

Posted on 2003-03-19
5
Medium Priority
?
167 Views
Last Modified: 2010-04-15
here is my program:

#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include "a:\queue.h"
#include "a:\arrstack.h"

void transfer(int a,STACK S,STACK S1);
void compute(QUEUE Q,STACK S);
int token(char *str,QUEUE Q,STACK S);

void main()
 {
     char *str;
     int a,size=10;
     QUEUE Q;
     STACK S,S1;
     clrscr();
     clrscr();
     Q=createqueue(size);
     S=createstack(size);
     S1=createstack(size);
     printf("ENTER A INFIX EXPRESSION : ");
     gets(str);
     transfer(a,S,S1);
     compute(Q,S1);
     a=token(str,Q,S);
     getch();
 }

int token(char *str,QUEUE Q,STACK S)
 {
     char *temp;
     float j;
     int len,i,x=0,a=0,z,b=0;
     len=strlen(str);

  errorcheck(str[0]==' '||str[0]=='/'||str[0]=='*',"INVALID EXPRESSION");
  errorcheck(str[len-1]=='-'||str[len-1]=='/'||str[len-1]=='*'
                   ||str[len-1]=='+',"INVALID EXPRESSION");

     for(i=0;i<len;i++)
      {
     if(str[i]==' ')
      {
          x++;
      }
     else
      if(x==1)
          {
           enqueue(str[i],Q);
           temp[a]=NULL;
           z=strlen(temp);
           a=atof(temp);
           errorcheck(z>1&&j==0,"INVALID EXPRESSION");
           push(j,S);
           a=0;b++;
          }
          else
           if((x==0||x==2)&&(str[i]=='+'||str[i]=='-' ))
               {
                temp[a]=str[i];
                a++;
               }
          else
           {
               temp[a]=str[i];
               a++;
           }
          if(x==2)
           x=0;
           }
      temp[a]=NULL;
      z=strlen(temp);
      j=atof(temp);
      errorcheck(z>1&&j==0,"INVALID EXPRESSION");
      push(j,S);
      b++;
      return b;
 }

void transfer(int a,STACK S,STACK S1)
 {
     int x=0;
     while(a>x)
      {
         push(stacktop(S),S1);
         pop(S);
         x++;
      }
 }

void compute(QUEUE Q,STACK S1)
 {
     char s;
     float a,b;
     a=stacktop(S1);
     pop(S1);
while(Q->front)
     {
     s=Qfront(Q);
     switch(s)
      {
      case '+': b=stacktop(S1);
          a+=b;
          pop(S1);
          break;
      case '-': b=stacktop(S1);
          a-=b;
          pop(S1);
          break;
      case '*': b=stacktop(S1);
          a*=b;
          pop(S1);
          break;
      case '/': b=stacktop(S1);
          a/=b;
          pop(S1);
          break;

      default :
      printf("INVALID EXPRESSION ");
      getch();
      exit(1);
      }
      dequeue(Q);
      }
printf("\nTOTAL = %.2f",a);
}
0
Comment
Question by:JUNMAR
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 8165287
>> errorcheck(str[0]==' '||str[0]=='/'||str[0]=='*',"INVALID EXPRESSION");

Is this function defined in the header files "queue.h" or "arrstack.h" that you have included? You may have defined it twice (in both of them).

What platform are you working upon?

Mayank.
0
 
LVL 30

Accepted Solution

by:
Mayank S earned 160 total points
ID: 8165319
>> errorcheck(str[0]==' '||str[0]=='/'||str[0]=='*',"INVALID EXPRESSION");

Do you intend to do:

if ( str[0] == ' ' || str[0] == '/' || str[0] == '*' )
  printf ( "\n Invalid expression. " ) ; // end if

Mayank.
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10058906
Nothing has happened on this question in more than 13 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by mayankeagle.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10060406
Please go ahead with that recommendation.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question