This problem is asking me to convert an infix expression to a postfix expression using recursion. I did the exact same problem using stacks (w/o recursion), which was much easier, but on this one, I get stumped constantly when I try to come up with a line of code to call the function(itself) again. So far, what I've come up with is not really a true recursion function as it does not return a value =\ Thanks for any tips you guys can give. (And sorry if the code in the brackets is too compact).
fyi: The format of the input has to be something like (5*9) or it won't work.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define LEN 100
static char input[LEN], hold[LEN];
static int i, j, cnt;
void eval();
int main(void)
{
puts("Enter an infix expression:");
fgets(input, LEN, stdin);
eval();
return 0;
}
void eval()
{
int x = 0;
if (input[i] == '(') i++;
if (input[i] == ')')
{
printf("%c", hold[--j]);
i++;
}
if (input[i] == '*' || input[i] == '+')
{ hold[j++] = input[i]; i++; }
while (isdigit(input[i]))
{
x = 10*x + (input[i++]-'0');
printf("%d", x);
}
eval();
}