|
Answer» I am working on this program to calculate arithmetic questions but I seem to be havin some problem, I used typedefine to define an array and then when I use it as a function prototype it keeps on telling me that it is an illegal expression. I am posting the problematic part only the whole code is tooooooooo long like 600 lines!!!
#define MAXLEN 50
//the typedefinitions typedef char mystr[MAXLEN]; typedef char exprstr[MAXLEN];
//the function prototypes int precedence(mystr s); //to return precedence in terms of integers of the operator void trimspace(char *s); // to remove the space in the input expression void createinfix (mystr s); //create the infix expression based on the input expression int isoperator(char c); //to check whether the CHARACTER is an operator void dumpexpr(expr ); // display the expression for debugging expr *convert2postfix(expr ); //convert the infix to postfix void push(expr, int *, mystr); //push an item onto the stack mystr *pop(expr, int *); // pop and return an item from the stack void enqueue(expr, int *, int *, mystr); // enqueue an item to the queue mystr *dequeue(expr, int *, int *); // dequeue and return an item from the queue void initialexpr(expr); // initial the expression array with null strings void copyexpr(expr,expr); //copy one expression to the other float evaluatepostfix(expr);
The problem is with the funtion mystr*pop(expr, int *); in compilation it keeps on telling me that it is an illegal expression I just don't know what is the problem with this thing...would somebody please help me it's really starting to get to me!!!Oh and I am using lcc win32 compiler if that's any help!I have no idea what you are doing! But if I needed an function that I can not defile in the language, I would write it in machine code and put it in a library, or something like that. Hint: If compilers bug you, don't use compilers. Write in some High Level thing that you can debug line by line. Like maybe Delphi or java or something like that. Why TORMENT yourself with C or whatever you are using unless it has an interactive debugger. Also called Interactive Development Environment. You type something and right away it shows you what is bad and what is good. And don't do 600 lines and find that it does not work. Crunch it down to maybe 50 lines of code and test it and put it into your own library as a proven function. Number 1 I have to use C because that's the language I learned and I would totally have to rewrite the whole thing if I use another compiler or whatever. And yes I am checking the whole thing bit by bit by breaking the function and it is working just the real thing won't go any further because it is stuck at this error!!!THANKS for the advice anyway Sorry I can not help you. Can you get an Interactive C program that will show you just what is wrong? Or, do you have a 'lint' program that will nag you about your logic and structure? A general rule is first get it to work, then make it better, faster and smoother. Using pointers is a real chore. How about writing the program so that you use an index rather than a pointer. Or PASSING value instead of pointers? Yeah pointers are better. But index and value is easier to debug. Also, you are using #define. That's OK, but you can get by WITHOUT it and ome C compilers can choke on it because it can not do the replacement in some cases. Instead, use a global integer and set its value in the main() part of your code. Yeah, not true blue C, but easier to debug. What I am saying is make the code so simple and dumb that even your grandma would understand it. You can do it, just keep it simple. An even when done that way it is still smaller and faster than a high level language. OK,I don't know what I am talking about. I just know that when you try another route, things start to work. And I still that that you should put as much as you can into a library once it has been validated. And turn on all the debug tools of the compiler. Also, do you have some similar code that compiles perfect? Is it the compiler you always use? Are you one a new version of the OS? Does the compiler require something odd for the OS you are using? Just a thought. Hope you get it, Maybe somebody else has an idea.
|