Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

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

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
JUNMAR
Asked:
JUNMAR
  • 3
1 Solution
 
Mayank SAssociate Director - Product EngineeringCommented:
>> 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
 
Mayank SAssociate Director - Product EngineeringCommented:
>> 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
 
jmcgOwnerCommented:
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
 
Mayank SAssociate Director - Product EngineeringCommented:
Please go ahead with that recommendation.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now